cartodb-4.42/lib/assets/javascripts/builder/dataset/data-sql-model.js

44 lines
828 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
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'
);
}
});