mirror of
https://github.com/frappe/books.git
synced 2025-01-10 18:24:40 +00:00
fix for add column, observable
This commit is contained in:
parent
7c6ddcd3e5
commit
415389bca0
@ -65,7 +65,7 @@ module.exports = class Database extends Observable {
|
||||
await this.addColumns(doctype, newColumns);
|
||||
}
|
||||
if (newForeignKeys.length) {
|
||||
await this.addForeignKeys(doctype);
|
||||
await this.addForeignKeys(doctype, newForeignKeys);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,16 +28,7 @@ module.exports = class sqliteDatabase extends Database {
|
||||
return (name && name.length) ? true : false;
|
||||
}
|
||||
|
||||
async alterTable(doctype) {
|
||||
let newColumns = await this.getNewColumns(doctype);
|
||||
let newForeignKeys = await this.getNewForeignKeys(doctype);
|
||||
|
||||
if (newColumns.length || newForeignKeys.length) {
|
||||
await this.migrateToNewTable(doctype);
|
||||
}
|
||||
}
|
||||
|
||||
async migrateToNewTable(doctype) {
|
||||
async addForeignKeys(doctype, newForeignKeys) {
|
||||
await this.run('PRAGMA foreign_keys=OFF');
|
||||
await this.run('BEGIN TRANSACTION');
|
||||
|
||||
@ -65,6 +56,16 @@ module.exports = class sqliteDatabase extends Database {
|
||||
}
|
||||
|
||||
updateColumnDefinition(field, columns, indexes) {
|
||||
let def = this.getColumnDefinition(field);
|
||||
|
||||
columns.push(def);
|
||||
|
||||
if (field.fieldtype==='Link' && field.target) {
|
||||
indexes.push(`FOREIGN KEY (${field.fieldname}) REFERENCES ${field.target} ON UPDATE RESTRICT ON DELETE RESTRICT`);
|
||||
}
|
||||
}
|
||||
|
||||
getColumnDefinition(field) {
|
||||
let def = `${field.fieldname} ${this.type_map[field.fieldtype]}`;
|
||||
if (field.fieldname==='name') {
|
||||
def += ' PRIMARY KEY NOT NULL';
|
||||
@ -75,12 +76,7 @@ module.exports = class sqliteDatabase extends Database {
|
||||
if (field.default) {
|
||||
def += `DEFAULT ${field.default}`;
|
||||
}
|
||||
|
||||
columns.push(def);
|
||||
|
||||
if (field.fieldtype==='Link' && field.target) {
|
||||
indexes.push(`FOREIGN KEY (${field.fieldname}) REFERENCES ${field.target} ON UPDATE RESTRICT ON DELETE RESTRICT`);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
async getTableColumns(doctype) {
|
||||
|
@ -27,14 +27,6 @@ html {
|
||||
border-left: 1px solid $gray-300;
|
||||
}
|
||||
|
||||
.desk-menu {
|
||||
|
||||
.list-group-item {
|
||||
padding: $spacer-2 $spacer-3;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none !important;
|
||||
}
|
||||
@ -108,6 +100,31 @@ html {
|
||||
padding: $spacer-2 $spacer-3;
|
||||
}
|
||||
|
||||
.desk-menu {
|
||||
background-color: $gray-200;
|
||||
|
||||
.list-row {
|
||||
border-bottom: 1px solid $gray-200;
|
||||
}
|
||||
|
||||
.list-row:hover {
|
||||
background-color: $gray-300;
|
||||
}
|
||||
|
||||
.list-row.active {
|
||||
background-color: $gray-400;
|
||||
}
|
||||
}
|
||||
|
||||
.print-page {
|
||||
padding: $spacer-5;
|
||||
line-height: 1.8;
|
||||
|
||||
td, th {
|
||||
padding: $spacer-2;
|
||||
}
|
||||
}
|
||||
|
||||
.CodeMirror {
|
||||
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
||||
border: 1px solid $gray-300;
|
||||
@ -194,12 +211,3 @@ mark {
|
||||
}
|
||||
}
|
||||
|
||||
.print-page {
|
||||
padding: $spacer-5;
|
||||
line-height: 1.8;
|
||||
|
||||
td, th {
|
||||
padding: $spacer-2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,15 @@ module.exports = class Observable {
|
||||
}
|
||||
|
||||
async trigger(event, params, throttle=false) {
|
||||
if (this._throttled(event, params, throttle)) return;
|
||||
if (throttle) {
|
||||
if (this._throttled(event, params, throttle)) return;
|
||||
params = [params]
|
||||
}
|
||||
|
||||
// listify if throttled
|
||||
if (throttle) params = [params];
|
||||
await this._executeTriggers(event, params);
|
||||
}
|
||||
|
||||
async _executeTriggers(event, params) {
|
||||
await this._triggerEvent('_listeners', event, params);
|
||||
await this._triggerEvent('_onceListeners', event, params);
|
||||
|
||||
@ -52,40 +56,31 @@ module.exports = class Observable {
|
||||
if (this._onceListeners && this._onceListeners[event]) {
|
||||
delete this._onceListeners[event];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
_throttled(event, params, throttle) {
|
||||
if (throttle) {
|
||||
if (this._isHot[event]) {
|
||||
if (this._isHot[event]) {
|
||||
// hot, add to queue
|
||||
if (!this._eventQueue[event]) this._eventQueue[event] = [];
|
||||
this._eventQueue[event].push(params);
|
||||
|
||||
// hot, add to queue
|
||||
if (this._eventQueue[event]) {
|
||||
|
||||
// queue exists, just add
|
||||
this._eventQueue[event].push(params);
|
||||
} else {
|
||||
|
||||
// create a new queue to be called after cool-off
|
||||
this._eventQueue[event] = [params];
|
||||
|
||||
// call after cool-off
|
||||
setTimeout(() => {
|
||||
let _queuedParams = this._eventQueue[event];
|
||||
|
||||
// reset queues
|
||||
this._isHot[event] = false;
|
||||
this._eventQueue[event] = null;
|
||||
|
||||
this.trigger(event, _queuedParams, true);
|
||||
}, throttle);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
this._isHot[event] = true;
|
||||
// aleady hot, quit
|
||||
return true;
|
||||
}
|
||||
this._isHot[event] = true;
|
||||
|
||||
// cool-off
|
||||
setTimeout(() => {
|
||||
this._isHot[event] = false;
|
||||
|
||||
// flush queue
|
||||
if (this._eventQueue[event]) {
|
||||
let _queuedParams = this._eventQueue[event];
|
||||
this._eventQueue[event] = null;
|
||||
this._executeTriggers(event, _queuedParams);
|
||||
}
|
||||
}, throttle);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user