Skip to content

Instantly share code, notes, and snippets.

@Mariusio
Created February 10, 2016 17:23
Show Gist options
  • Save Mariusio/f6eb0fcb66fd37231423 to your computer and use it in GitHub Desktop.
Save Mariusio/f6eb0fcb66fd37231423 to your computer and use it in GitHub Desktop.
deleteVisualizations: function() {
return new Promise((resolve, reject) => {
this.get('visualizations').then((visualizations) => {
// Initiate array to store IDs and types of visualizations to be removed
var arr = [];
visualizations.forEach((visualization, index, visualizations) => {
var id = visualization.get('id');
var modelName = visualization.get('constructor.modelName');
var newArr = []
newArr.pushObject(modelName);
newArr.pushObject(id);
arr.pushObject(newArr);
});
// Iterate over newly created array and remove each element
arr.forEach((element) => {
var record = this.store.peekRecord(element[0], element[1]);
this.store.unloadRecord(record);
});
resolve();
});
});
},
deleteInactiveVisualizations: function() {
return new Promise((resolve, reject) => {
this.get('visualizations').filterBy('active', false).then((visualizations) => {
// Initiate array to store IDs and types of visualizations to be removed
var arr = [];
visualizations.forEach((visualization, index, visualizations) => {
var id = visualization.get('id');
var modelName = visualization.get('constructor.modelName');
var newArr = []
newArr.pushObject(modelName);
newArr.pushObject(id);
arr.pushObject(newArr);
});
// Iterate over newly created array and remove each element
arr.forEach((element) => {
var record = this.store.peekRecord(element[0], element[1]);
this.store.unloadRecord(record);
});
resolve();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment