From 7677fe9f806e9c8da0b8b8bf0dbea404e329cdf8 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Oct 2022 14:01:00 +0800 Subject: [PATCH] feat(nocodb-sdk): add cover image to kanban --- .../src/lib/migrations/XcMigrationSourcev2.ts | 4 ++ ...nc_022_add_kanban_fk_cover_image_col_id.ts | 41 +++++++++++++++++++ packages/nocodb/src/lib/models/KanbanView.ts | 10 ++++- packages/nocodb/src/lib/models/View.ts | 21 +++------- 4 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 packages/nocodb/src/lib/migrations/v2/nc_022_add_kanban_fk_cover_image_col_id.ts diff --git a/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts b/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts index df383beec0..6d25a31f7b 100644 --- a/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts +++ b/packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts @@ -9,6 +9,7 @@ import * as nc_018_add_meta_in_view from './v2/nc_018_add_meta_in_view'; import * as nc_019_add_meta_in_meta_tables from './v2/nc_019_add_meta_in_meta_tables'; import * as nc_020_add_kanban_meta_col from './v2/nc_020_add_kanban_meta_col'; import * as nc_021_rename_kanban_grp_col_id from './v2/nc_021_rename_kanban_grp_col_id'; +import * as nc_022_add_kanban_fk_cover_image_col_id from './v2/nc_022_add_kanban_fk_cover_image_col_id'; // Create a custom migration source class export default class XcMigrationSourcev2 { @@ -29,6 +30,7 @@ export default class XcMigrationSourcev2 { 'nc_019_add_meta_in_meta_tables', 'nc_020_add_kanban_meta_col', 'nc_021_rename_kanban_grp_col_id', + 'nc_022_add_kanban_fk_cover_image_col_id' ]); } @@ -60,6 +62,8 @@ export default class XcMigrationSourcev2 { return nc_020_add_kanban_meta_col; case 'nc_021_rename_kanban_grp_col_id': return nc_021_rename_kanban_grp_col_id; + case 'nc_022_add_kanban_fk_cover_image_col_id': + return nc_022_add_kanban_fk_cover_image_col_id; } } } diff --git a/packages/nocodb/src/lib/migrations/v2/nc_022_add_kanban_fk_cover_image_col_id.ts b/packages/nocodb/src/lib/migrations/v2/nc_022_add_kanban_fk_cover_image_col_id.ts new file mode 100644 index 0000000000..e7c068a7d3 --- /dev/null +++ b/packages/nocodb/src/lib/migrations/v2/nc_022_add_kanban_fk_cover_image_col_id.ts @@ -0,0 +1,41 @@ +import Knex from 'knex'; +import { MetaTable } from '../../utils/globals'; + +const up = async (knex: Knex) => { + await knex.schema.alterTable(MetaTable.KANBAN_VIEW, (table) => { + table.string('fk_cover_image_col_id', 20); + table + .foreign('fk_cover_image_col_id') + .references(`${MetaTable.COLUMNS}.id`); + }); +}; + +const down = async (knex) => { + await knex.schema.alterTable(MetaTable.KANBAN_VIEW, (table) => { + table.dropColumns('fk_cover_image_col_id'); + }); +}; + +export { up, down }; + +/** + * @copyright Copyright (c) 2021, Xgene Cloud Ltd + * + * @author Wing-Kam Wong + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ diff --git a/packages/nocodb/src/lib/models/KanbanView.ts b/packages/nocodb/src/lib/models/KanbanView.ts index 13da0f4b4d..c583aa01af 100644 --- a/packages/nocodb/src/lib/models/KanbanView.ts +++ b/packages/nocodb/src/lib/models/KanbanView.ts @@ -1,5 +1,5 @@ import Noco from '../Noco'; -import { KanbanType } from 'nocodb-sdk'; +import { KanbanType, UITypes } from 'nocodb-sdk'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import View from './View'; import NocoCache from '../cache/NocoCache'; @@ -10,6 +10,7 @@ export default class KanbanView implements KanbanType { project_id?: string; base_id?: string; fk_grp_col_id?: string; + fk_cover_image_col_id?: string; meta?: string | object; // below fields are not in use at this moment @@ -58,11 +59,18 @@ export default class KanbanView implements KanbanType { } static async insert(view: Partial, ncMeta = Noco.ncMeta) { + const columns = await View.get(view.fk_view_id, ncMeta) + .then((v) => v?.getModel(ncMeta)) + .then((m) => m.getColumns(ncMeta)); + const insertObj = { project_id: view.project_id, base_id: view.base_id, fk_view_id: view.fk_view_id, fk_grp_col_id: view.fk_grp_col_id, + fk_cover_image_col_id: + view?.fk_cover_image_col_id || + columns?.find((c) => c.uidt === UITypes.Attachment)?.id, meta: view.meta, }; diff --git a/packages/nocodb/src/lib/models/View.ts b/packages/nocodb/src/lib/models/View.ts index 9ca45bf1d7..3e79eb0bba 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/packages/nocodb/src/lib/models/View.ts @@ -355,8 +355,7 @@ export default class View implements ViewType { { let order = 1; let galleryShowLimit = 0; - let kanbanShowCount = 0; - let kanbanAttachmentCount = 0; + let kanbanShowLimit = 0; if (view.type === ViewTypes.KANBAN && !copyFromView) { // sort by primary value & attachment first, then by singleLineText & Number @@ -401,22 +400,14 @@ export default class View implements ViewType { if (vCol.id === kanbanView?.fk_grp_col_id) { // include grouping field if it exists show = true; - } else if (vCol.pv) { - // Show primary key + } else if (vCol.id === kanbanView.fk_cover_image_col_id || vCol.pv) { + // Show cover image or primary key show = true; - kanbanShowCount++; - } else if ( - vCol.uidt === UITypes.Attachment && - kanbanAttachmentCount < 1 - ) { - // Show at most 1 attachment - show = true; - kanbanAttachmentCount++; - kanbanShowCount++; - } else if (kanbanShowCount < 3 && !isSystemColumn(vCol)) { + kanbanShowLimit++; + } else if (kanbanShowLimit < 3 && !isSystemColumn(vCol)) { // show at most 3 non-system columns show = true; - kanbanShowCount++; + kanbanShowLimit++; } else { // other columns will be hidden show = false;