Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate new courses so that they can be previewed #1683

Merged
merged 7 commits into from
Aug 21, 2017

Conversation

canstudios-nicolaw
Copy link
Contributor

Fixes #1678

When you create a course the new course contains a page, article, block and text component. This means that the course can be previewed immediately.

I've put some text in the text component for now which I don't think will be final. We discussed some sort of welcome text in the stand up but didn't specify what it would be. Do we want just a straightforward 'This is an adapt course' type message or something a little more detailed that explains ABC?

@canstudios-nicolaw canstudios-nicolaw added this to the 0.4.0 Refactor milestone Jul 24, 2017
@@ -0,0 +1,24 @@
// LICENCE https://github.com/adaptlearning/adapt_authoring/blob/master/LICENSE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file will be necessary after the refactor PR

@dancgray
Copy link
Member

Block layoutOptions are not populated. Not sure if that matters? Otherwise looks good.

@canstudios-nicolaw
Copy link
Contributor Author

I wondered about that to. It didn't seem to do any harm when I took them out, so I left them out. Am happy to put them back in if that's the standard thing though

@canstudios-nicolaw
Copy link
Contributor Author

I have added the block layout options to be on the safe side.

(I'm off next week so I don't want things waiting on me)

@taylortom taylortom self-requested a review July 28, 2017 17:01
componentModel.save({
_courseId: model.get('_id'),
_parentId: blockModel.get('_id'),
body: 'This is a text component',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would ne nice if we can make this localizable ... or maybe use "Lorem ipsum ..." instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, think that's a good idea @lc-thomasberger

@taylortom
Copy link
Member

Just noticed that various colorPicker assets have changed permissions, was this intentional?

@canstudios-louisem
Copy link
Contributor

canstudios-louisem commented Aug 9, 2017

No im not sure how that even happened must have been during the rebase.

Copy link
Member

@taylortom taylortom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All works well :)

Could we maybe remove the nesting in the main function for readability? Something like:

populateNewCourse: function(model, response, options) {
  this.createGenericPage(model);
},

createGenericPage: function(courseModel) {
  var contentObjectModel = new ContentObjectModel({
    title: Origin.l10n.t('app.placeholdernewpage'),
    displayTitle: Origin.l10n.t('app.placeholdernewpage'),
    _type: 'page',
    _courseId: courseModel.get('_id'),
    _parentId: courseModel.get('_id')
  });
  contentObjectModel.save(null, {
    error: _.bind(this.onSaveError, this),
    success: _.bind(this.createGenericArticle, this)
  });
},

createGenericArticle: function(pageModel) {
  var articleModel = new ArticleModel({
    _courseId: pageModel.get('_courseId'),
    _parentId: pageModel.get('_id'),
    _type: 'article'
  });
  articleModel.save(null, {
    error: _.bind(this.onSaveError, this),
    success: _.bind(this.createGenericBlock, this)
  });
},

createGenericBlock: function(articleModel) {
  var blockModel = new BlockModel({
    _courseId: articleModel.get('_courseId'),
    _parentId: articleModel.get('_id'),
    _type: 'block',
    layoutOptions: [
      { type: 'left', name: 'app.layoutleft', pasteZoneRenderOrder: 2 },
      { type: 'full', name: 'app.layoutfull', pasteZoneRenderOrder: 1 },
      { type: 'right', name: 'app.layoutright', pasteZoneRenderOrder: 3 }
    ]
  });
  blockModel.save(null, {
    error: _.bind(this.onSaveError, this),
    success: _.bind(this.createGenericComponent, this)
  });
},

createGenericComponent: function(blockModel) {
  // Store the component types
  var componentTypes = new EditorCollection(null, {
    model: ComponentTypeModel,
    url: '/api/componenttype',
    _type: 'componentTypes'
  });
  componentTypes.fetch({
    error: _.bind(this.onSaveError, this),
    success: _.bind(function() {
      var componentModel = new ComponentModel({
        _courseId: blockModel.get('_courseId'),
        _parentId: blockModel.get('_id'),
        body: Origin.l10n.t('app.projectcontentbody'),
        _type: 'component',
        _component: 'text',
        _componentType: componentTypes.findWhere({ component: 'text' }).attributes._id,
        _layout: 'full'
      });
      componentModel.save(null, {
        error: _.bind(this.onSaveError, this),
        success: function() {
          Origin.router.navigateTo('/editor/' + componentModel.get('_courseId') + '/menu');
        }
      });
    }, this)
  });
}

@canstudios-louisem canstudios-louisem dismissed their stale review August 10, 2017 10:30

I have made changes on the pr since i reviewed it initially

@canstudios-nicolaw
Copy link
Contributor Author

@taylortom I've refactored as per your suggestion (thanks for the code!). We have removed those colourPicker asset changes - sorry we didn't notice those as they didn't show on bitbucket.

@taylortom taylortom requested review from lc-thomasberger and removed request for dancgray August 10, 2017 13:46
var contentObjectModel = new ProjectContentObjectModel();
contentObjectModel.save({
title: 'Page Title',
displayTitle: 'Page Title',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localizable Strings would be nice.

@taylortom taylortom merged commit e0f10db into adaptlearning:develop Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants