Browse Source

feat(nocodb-sdk): add cover image to kanban

pull/4003/head
Wing-Kam Wong 2 years ago
parent
commit
7677fe9f80
  1. 4
      packages/nocodb/src/lib/migrations/XcMigrationSourcev2.ts
  2. 41
      packages/nocodb/src/lib/migrations/v2/nc_022_add_kanban_fk_cover_image_col_id.ts
  3. 10
      packages/nocodb/src/lib/models/KanbanView.ts
  4. 21
      packages/nocodb/src/lib/models/View.ts

4
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;
}
}
}

41
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 <wingkwong.code@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

10
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<KanbanView>, 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,
};

21
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;

Loading…
Cancel
Save