Lists list and CUD
Custom forms list Updated DB schema (not yet implemented in the server, which means that most of the server is not broken). - custom forms are independent of a list - order and visibility of fields is now in custom_fields - first_name and last_name has been turned to a regular custom field
This commit is contained in:
parent
216fe40b53
commit
f6e1938ff9
47 changed files with 1245 additions and 122 deletions
|
@ -1,8 +1,6 @@
|
|||
exports.up = function(knex, Promise) {
|
||||
const entityTypesAddNamespace = ['list', 'report', 'report_template', 'user'];
|
||||
let schema = knex.schema;
|
||||
|
||||
schema = schema.createTable('namespaces', table => {
|
||||
const entityTypesAddNamespace = ['list', 'custom_form', 'report', 'report_template', 'user'];
|
||||
let promise = knex.schema.createTable('namespaces', table => {
|
||||
table.increments('id').primary();
|
||||
table.string('name');
|
||||
table.text('description');
|
||||
|
@ -10,12 +8,12 @@ exports.up = function(knex, Promise) {
|
|||
})
|
||||
.then(() => knex('namespaces').insert({
|
||||
id: 1, /* Global namespace id */
|
||||
name: 'Global',
|
||||
description: 'Global namespace'
|
||||
name: 'Root',
|
||||
description: 'Root namespace'
|
||||
}));
|
||||
|
||||
for (const entityType of entityTypesAddNamespace) {
|
||||
schema = schema
|
||||
promise = promise
|
||||
.then(() => knex.schema.table(`${entityType}s`, table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
|
@ -27,7 +25,7 @@ exports.up = function(knex, Promise) {
|
|||
}));
|
||||
}
|
||||
|
||||
return schema;
|
||||
return promise;
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const shareableEntityTypes = ['list', 'report', 'report_template', 'namespace'];
|
||||
const shareableEntityTypes = ['list', 'custom_form', 'report', 'report_template', 'namespace'];
|
||||
|
||||
exports.up = function(knex, Promise) {
|
||||
let schema = knex.schema;
|
||||
|
@ -9,6 +9,7 @@ exports.up = function(knex, Promise) {
|
|||
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`).onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('role', 128).notNullable();
|
||||
table.boolean('auto').defaultTo(false);
|
||||
table.primary(['entity', 'user']);
|
||||
})
|
||||
.createTable(`permissions_${entityType}`, table => {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.table('custom_forms_data', table => {
|
||||
table.dropColumn('id');
|
||||
table.string('data_key', 128).alter();
|
||||
table.primary(['form', 'data_key']);
|
||||
})
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.table('custom_forms', table => {
|
||||
table.dropForeign('list', 'custom_forms_ibfk_1');
|
||||
table.dropColumn('list');
|
||||
})
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
};
|
|
@ -0,0 +1,97 @@
|
|||
"use strict";
|
||||
|
||||
exports.up = (knex, Promise) => (async() => {
|
||||
await knex.schema.table('custom_fields', table => {
|
||||
table.integer('order_subscribe');
|
||||
table.integer('order_manage');
|
||||
table.integer('order_list');
|
||||
});
|
||||
|
||||
await knex.schema.table('subscription', table => {
|
||||
table.dropColumn('first_name');
|
||||
table.dropColumn('last_name');
|
||||
});
|
||||
|
||||
const lists = await knex('lists')
|
||||
.leftJoin('custom_forms', 'lists.default_form', 'custom_forms.id')
|
||||
.select(['lists.id', 'lists.default_form', 'custom_forms.fields_shown_on_subscribe', 'custom_forms.fields_shown_on_manage']);
|
||||
|
||||
for (const list of lists) {
|
||||
const fields = await knex('custom_fields').where('list', list.id).orderBy('id', 'asc');
|
||||
|
||||
const [firstNameFieldId] = await knex('custom_fields').insert({
|
||||
list: list.id,
|
||||
name: 'First Name',
|
||||
key: 'FIRST_NAME',
|
||||
type: 'text',
|
||||
column: 'first_name',
|
||||
visible: 1 // FIXME - Revise the need for this field
|
||||
});
|
||||
|
||||
const [lastNameFieldId] = await knex('custom_fields').insert({
|
||||
list: list.id,
|
||||
name: 'Last Name',
|
||||
key: 'LAST_NAME',
|
||||
type: 'text',
|
||||
column: 'last_name',
|
||||
visible: 1 // FIXME - Revise the need for this field
|
||||
});
|
||||
|
||||
let orderSubscribe;
|
||||
let orderManage;
|
||||
|
||||
const replaceNames = x => {
|
||||
if (x === 'firstname') {
|
||||
return firstNameFieldId;
|
||||
} else if (x === 'lastname') {
|
||||
return lastNameFieldId;
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
if (list.default_form) {
|
||||
orderSubscribe = list.fields_shown_on_subscribe.split(',').map(replaceNames);
|
||||
orderManage = list.fields_shown_on_subscribe.split(',').map(replaceNames);
|
||||
} else {
|
||||
orderSubscribe = [firstNameFieldId, lastNameFieldId];
|
||||
orderManage = [firstNameFieldId, lastNameFieldId];
|
||||
|
||||
for (const fld of fields) {
|
||||
if (fld.visible && fld.type !== 'option') {
|
||||
orderSubscribe.push(fld.id);
|
||||
orderManage.push(fld.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const orderList = [firstNameFieldId, lastNameFieldId];
|
||||
|
||||
let idx = 0;
|
||||
for (const fldId of orderSubscribe) {
|
||||
await knex('custom_fields').where('id', fldId).update({order_subscribe: idx});
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
for (const fldId of orderManage) {
|
||||
await knex('custom_fields').where('id', fldId).update({order_manage: idx});
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
for (const fldId of orderList) {
|
||||
await knex('custom_fields').where('id', fldId).update({order_list: idx});
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
await knex.schema.table('custom_forms', table => {
|
||||
table.dropColumn('fields_shown_on_subscribe');
|
||||
table.dropColumn('fields_shown_on_manage');
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue