cartodb/lib/assets/javascripts/builder/dataset/data-sql-model.js
2020-06-15 10:58:47 +08:00

44 lines
828 B
JavaScript
Executable File

var Backbone = require('backbone');
var _ = require('underscore');
var UndoManager = require('builder/data/undo-manager.js');
/**
* Data SQL Undo-redo model
*/
module.exports = Backbone.Model.extend({
defaults: {
content: ''
},
initialize: function (attrs, opts) {
this._history = this._generateHistory(opts && opts.history);
UndoManager.init(this, {
track: true,
history: this._history
});
},
_generateHistory: function (history) {
if (history && history.length) {
var data = _.reduce(history, function (memo, sql) {
memo.push({
content: sql
});
return memo;
}, [], this);
return data;
}
return false;
},
getHistory: function () {
return _.pluck(
this.getUndoHistory(),
'content'
);
}
});