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

issue/2758 Added deepClone API (v5.7.0) #2759

Merged
merged 73 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
87a4534
issue/2709 Converted some classes to ES6 for future works
oliverfoster Mar 31, 2020
80787b1
issue/2709 fixed locking model for ES6 classes
oliverfoster Mar 31, 2020
5a686db
Recommendations
oliverfoster Apr 1, 2020
603d332
Recommendations
oliverfoster Apr 1, 2020
c368971
Recommendations
oliverfoster Apr 1, 2020
ce81506
Recommendation
oliverfoster Apr 1, 2020
6681597
Recommendation
oliverfoster Apr 1, 2020
d50d146
Recommendations
oliverfoster Apr 1, 2020
d4aad08
issue/2712 Simplfied router
oliverfoster Apr 1, 2020
8933d4e
Fixed bugs added comments
oliverfoster Apr 1, 2020
0375144
Added defer to postRemove events as expected
oliverfoster Apr 1, 2020
4db8f12
Removed bad condition
oliverfoster Apr 1, 2020
068d28d
Switched to cached value
oliverfoster Apr 1, 2020
551d458
Recommendations
oliverfoster Apr 2, 2020
4911dbb
Recommendations
oliverfoster Apr 2, 2020
749353f
Recommendations
oliverfoster Apr 2, 2020
81cacf1
issue/2714 Decoupled menu, page, article, block and component
oliverfoster Apr 2, 2020
64274b7
Typo
oliverfoster Apr 2, 2020
2de000f
Recommendations
oliverfoster Apr 4, 2020
1942b1a
issue/2714: Added Adapt.log.warnOnce
oliverfoster Apr 6, 2020
347f520
Linting fixes
oliverfoster Apr 6, 2020
96bda87
issue/2714 Added fallback model/view name discovery
oliverfoster Apr 6, 2020
ebdabc5
issue/2645 Added manifest creation and loading
oliverfoster Apr 6, 2020
dfb9224
Fixed issue with new compatibility layer changes
oliverfoster Apr 7, 2020
3b929b3
issue/2712 Simplfied router
oliverfoster Apr 1, 2020
df93b45
Fixed bugs added comments
oliverfoster Apr 1, 2020
763ccfc
Added defer to postRemove events as expected
oliverfoster Apr 1, 2020
eb6597a
Removed bad condition
oliverfoster Apr 1, 2020
eca527b
Switched to cached value
oliverfoster Apr 1, 2020
5a1cae8
Recommendations
oliverfoster Apr 2, 2020
c5b5bc4
Recommendations
oliverfoster Apr 2, 2020
a555e94
Recommendations
oliverfoster Apr 2, 2020
9fabc27
Merge branch 'issue/2712' of https://github.com/adaptlearning/adapt_f…
oliverfoster Apr 7, 2020
9a20e9b
issue/2714 Decoupled menu, page, article, block and component
oliverfoster Apr 2, 2020
53264e5
Typo
oliverfoster Apr 2, 2020
76cdf72
Recommendations
oliverfoster Apr 4, 2020
818dd05
issue/2714: Added Adapt.log.warnOnce
oliverfoster Apr 6, 2020
2bb469b
Linting fixes
oliverfoster Apr 6, 2020
b4abd4b
issue/2714 Added fallback model/view name discovery
oliverfoster Apr 6, 2020
be03dec
Merge branch 'issue/2714' of https://github.com/adaptlearning/adapt_f…
oliverfoster Apr 7, 2020
a861913
issue/2645 Added manifest creation and loading
oliverfoster Apr 6, 2020
c1130ae
Merge branch 'issue/2645' of https://github.com/adaptlearning/adapt_f…
oliverfoster Apr 7, 2020
d6dfe8d
Recommendations
olivermartinfoster Apr 14, 2020
4dd0ba8
Improved babel source mapping
olivermartinfoster Apr 14, 2020
3c7b656
Readded sourceType to babel config
olivermartinfoster Apr 14, 2020
cb1ee71
issue/2645 Added manifest creation and loading
olivermartinfoster Apr 14, 2020
cf924ca
isTypeGroup warning simplified
olivermartinfoster Apr 14, 2020
61c1a97
issue/2714 Decoupled menu, page, article, block and component
olivermartinfoster Apr 20, 2020
99d3aae
issue/2712 Simplified router
olivermartinfoster Apr 20, 2020
74e2b6c
Fix for authoring tool assets.json
olivermartinfoster Apr 21, 2020
9776793
Fixed linting issues
olivermartinfoster Apr 21, 2020
2af5448
Reworked AAT assets.json fix
olivermartinfoster Apr 21, 2020
e5e5157
Switched to native filter
olivermartinfoster Apr 21, 2020
014c62a
Switched from instanceof Array to Array.isArray
olivermartinfoster Apr 21, 2020
9529833
Fixed babel watch command
olivermartinfoster Apr 21, 2020
4d9a5c8
Added contentObject postRemove instance event, added global preReady …
olivermartinfoster Apr 21, 2020
3b0683c
Switched buttons and heading views to use contentObject postRemove in…
olivermartinfoster Apr 21, 2020
e756447
Added ready guard and removed duplicate preReady event
olivermartinfoster Apr 22, 2020
f1e632d
Moved _isReady reset back into Adapt.remove to allow multiple page re…
olivermartinfoster Apr 27, 2020
1c8ca18
ItemsQuestionModel not restoring question answers correctly, missing …
olivermartinfoster May 1, 2020
d7c85c4
resolved merge conflict
olivermartinfoster May 6, 2020
080b54b
issue/2758 Added deepClone API
olivermartinfoster May 9, 2020
316abd7
Fixed code comment
olivermartinfoster May 10, 2020
5b16ade
Merge branch 'master' into release/v5.6.0
olivermartinfoster May 12, 2020
1e6d2c8
Merged with master
olivermartinfoster May 22, 2020
4c69bf9
Merge branch 'release/v5.6.0' of https://github.com/adaptlearning/ada…
olivermartinfoster May 22, 2020
4768daa
issue/2758: Removed complexity
oliverfoster Jul 15, 2020
87bb0f0
issue/2758 Rework parent attachments
oliverfoster Jul 15, 2020
229d82a
Typo
oliverfoster Jul 15, 2020
390adb3
Merge branch 'master' into issue/2758
olivermartinfoster Jul 16, 2020
a4d8dc3
issue/2758 Recommendations and testing changes
olivermartinfoster Jul 16, 2020
6b12bf7
issue/2758 Typo
olivermartinfoster Jul 16, 2020
e7975a0
issue/2758 Return early
olivermartinfoster Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/core/js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,31 @@ define([
return new ModelClass(json);
}

initialize() {
super.initialize();
this.on({
'add': this.onAdded,
'remove': this.onRemoved
});
}

async init () {
this.reset();
this._byAdaptID = {};
Adapt.build = new BuildModel(null, { url: 'adapt/js/build.min.js', reset: true });
await Adapt.build.whenReady();
$('html').attr('data-adapt-framework-version', Adapt.build.get('package').version);
this.loadConfigData();
}

onAdded(model) {
this._byAdaptID[model.get('_id')] = model;
}

onRemoved(model) {
delete this._byAdaptID[model.get('_id')];
}

loadConfigData() {
Adapt.config = new ConfigModel(null, { url: 'course/config.' + Adapt.build.get('jsonext'), reset: true });
this.listenToOnce(Adapt, 'configModel:loadCourseData', this.onLoadCourseData);
Expand Down Expand Up @@ -122,8 +140,6 @@ define([
}
this.push(modelData);
});
// index by id
this._byAdaptID = this.indexBy('_id');
this.trigger('reset');
this.trigger('loaded');
await Adapt.wait.queue();
Expand All @@ -132,7 +148,9 @@ define([
async triggerDataLoaded() {
Adapt.log.debug('Firing app:dataLoaded');
try {
Adapt.trigger('app:dataLoaded');// Triggered to setup model connections in AdaptModel.js
// Setup the newly added models
this.forEach(model => model.setupModel && model.setupModel());
Adapt.trigger('app:dataLoaded');
} catch (e) {
Adapt.log.error('Error during app:dataLoading trigger', e);
}
Expand Down
54 changes: 49 additions & 5 deletions src/core/js/models/adaptModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ define([
];
}

initialize() {
// Wait until data is loaded before setting up model
this.listenToOnce(Adapt, 'app:dataLoaded', this.setupModel);
}

setupModel() {
if (this.hasManagedChildren) {
this.setupChildListeners();
Expand Down Expand Up @@ -695,6 +690,55 @@ define([
this.checkLocking();
}

/**
* Clones this model and all managed children returning a new branch.
* Assign new unique ids to each cloned model.
* Adds clone to Adapt.data and to their _parentId child lists.
* @param {Object} [set] Attributes to be set on the root clone
* @param {Object} [setOnChildren] Attributes to be set on the children clones.
* @param {Function} [modifier] A callback function for each child to allow further modifications
* @returns {AdaptModel}
*/
deepClone(set = {}, setOnChildren = {}, modifier = null) {
// Shallow clone the JSON and set overrides
const json = Object.assign({}, this.toJSON(), set);
// Fetch the class
const ModelClass = this.constructor;
const hasId = Boolean(json._id);
if (hasId) {
// Create a unique id if needed
const cid = _.uniqueId(ModelClass.prototype.cidPrefix || 'c');
json._id = `${cid}_${json._id}`;
}
// Clone the model
const clonedModel = new ModelClass(json);
// Add cloned model to Adapt.data for Adapt.findById resolution
hasId && Adapt.data.add(clonedModel);
// Clone any children
this.hasManagedChildren && this.getChildren().each(child => {
if (!child.deepClone) {
throw new Error('Cannot deepClone child.');
}
let set = setOnChildren;
if (hasId) {
// Pass through the new cloned parent id
set = Object.assign({}, setOnChildren, {
_parentId: json._id
});
}
return child.deepClone(set, setOnChildren, modifier);
});
if (hasId) {
// Add cloned model to its parent for findDescendants resolution
const parentModel = clonedModel.getParent();
parentModel && parentModel.getChildren().add(clonedModel);
}
// Setup the model after all the children have been added
modifier && modifier(this, clonedModel);
clonedModel.setupModel();
return clonedModel;
}

/**
* Internal event handler for all module events. Triggers event bubbling
* through the module hierarchy when the event is included in
Expand Down
4 changes: 2 additions & 2 deletions src/core/js/models/itemsQuestionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ define([
class BlendedItemsComponentQuestionModel extends QuestionModel {

init() {
super.init();
ItemsComponentModel.prototype.init.call(this);
super.init();
}

reset(type, force) {
super.reset(type, force);
ItemsComponentModel.prototype.reset.call(this, type, force);
super.reset(type, force);
}

}
Expand Down
6 changes: 5 additions & 1 deletion src/core/js/models/questionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ define([

init() {
this.setupDefaultSettings();
this.listenToOnce(Adapt, 'adapt:initialize', this.onAdaptInitialize);
if (Adapt.get('_isStarted')) {
this.onAdaptInitialize();
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.listenToOnce(Adapt, 'adapt:initialize', this.onAdaptInitialize);
}
}

// Calls default methods to setup on questions
Expand Down