UNPKG

@tanglemedia/directus-collection-modal

Version:

Installs the Modal Collection to your Directus project.

153 lines (145 loc) 3.52 kB
const MODAL_TABLE_NAME = "tngl_modal"; const MODAL_FIELDS_INSERTS = [ { collection: MODAL_TABLE_NAME, field: "timeout", special: null, interface: "input", options: { min: 0, step: 0.5, }, display: null, display_options: null, readonly: false, hidden: false, sort: 6, width: "full", translations: null, note: "How often you want the modal to show? The smaller the value, the more frequent the modal will show.", conditions: null, required: false, group: null, validation: null, validation_message: null, }, { collection: MODAL_TABLE_NAME, field: "buttons", special: ["cast-json"], interface: "list", options: { fields: [ { meta: { type: "string", field: "text", width: "full", interface: "input", }, name: "text", type: "string", field: "text", }, { meta: { type: "string", field: "url", width: "full", options: { softLength: 500, }, interface: "input", }, name: "url", type: "string", field: "url", }, ], template: "{{text}} - {{url}}", }, display: null, display_options: null, readonly: false, hidden: false, sort: 7, width: "full", translations: null, note: "Limit to 2 buttons per modal.", conditions: null, required: false, group: null, validation: null, validation_message: null, }, { collection: MODAL_TABLE_NAME, field: "type", special: null, interface: "select-dropdown", options: { choices: [ { text: "Default", value: "default", }, ], }, display: "labels", display_options: { choices: [ { text: "Default", value: "default", }, ], }, readonly: false, hidden: false, sort: 3, width: "full", translations: null, note: null, conditions: null, required: true, group: null, validation: null, validation_message: null, }, ]; export async function up(knex) { // add timeout, buttons, type column to tngl_modal table await knex.schema.alterTable(MODAL_TABLE_NAME, function (table) { table .specificType("timeout", "decimal(10,5)") .nullable() .defaultTo("0.50000"); table.json("buttons").nullable(); table.string("type", 255).notNullable().defaultTo("default"); }); // add new fields to directus_fields table await knex("directus_fields").insert(MODAL_FIELDS_INSERTS); } export async function down(knex) { // remove type from directus_fields table await knex("directus_fields") .where("collection", MODAL_TABLE_NAME) .andWhere("field", "type") .del(); // remove buttons from directus_fields table await knex("directus_fields") .where("collection", MODAL_TABLE_NAME) .andWhere("field", "buttons") .del(); // remove timeout from directus_fields table await knex("directus_fields") .where("collection", MODAL_TABLE_NAME) .andWhere("field", "timeout") .del(); // delete type, buttons, timeout columns from tngl_modal table await knex.schema.alterTable(MODAL_TABLE_NAME, function (table) { table.dropColumn("type"); table.dropColumn("buttons"); table.dropColumn("timeout"); }); }