Browse Source

fix: update record counter with insertion/deletion

Signed-off-by: Mert Ersoy <mertmit99@gmail.com>
pull/1620/head
Mert Ersoy 3 years ago
parent
commit
ff9db2dd72
  1. 8
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  2. 24
      packages/nocodb-sdk/src/lib/Api.ts
  3. 25
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts
  4. 69
      scripts/sdk/swagger.json

8
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -1157,6 +1157,7 @@ export default {
await this.$api.data.delete(this.meta.id, id)
}
this.data.splice(this.rowContextMenu.index, 1)
this.syncCount()
// this.$toast.success('Deleted row successfully').goAway(3000)
} catch (e) {
this.$toast.error(`Failed to delete row : ${e.message}`).goAway(3000)
@ -1187,6 +1188,7 @@ export default {
return this.$toast.error(`Failed to delete row : ${e.message}`).goAway(3000)
}
}
this.syncCount()
},
async clearCellValue() {
@ -1246,6 +1248,8 @@ export default {
this.expandRow(data.length - 1, rowMeta)
}
}
await this.save()
this.syncCount()
},
async handleKeyDown({
@ -1536,6 +1540,10 @@ export default {
console.log(e)
this.$toast.error(e.message).goAway(3000)
}
},
async syncCount() {
const { count } = await this.$api.dbViewRow.count('noco', this.$store.getters['project/GtrProjectName'], this.meta.title, this.selectedView.title)
this.count = count
}
},
computed: {

24
packages/nocodb-sdk/src/lib/Api.ts

@ -3122,6 +3122,30 @@ export class Api<
...params,
}),
/**
* No description
*
* @tags DB View Row
* @name Count
* @request GET:/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}/count
* @response `200` `any` OK
*/
count: (
orgs: string,
projectName: string,
tableAlias: string,
viewName: string,
query?: { where?: string; nested?: any },
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/data/${orgs}/${projectName}/${tableAlias}/views/${viewName}/count`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* No description
*

25
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts

@ -14,6 +14,27 @@ export async function dataList(req: Request, res: Response) {
res.json(await getDataList(model, view, req));
}
async function dataCount(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const countArgs: any = { ...req.query };
try {
countArgs.filterArr = JSON.parse(countArgs.filterArrJson);
} catch (e) {}
const count = await baseModel.count(countArgs);
res.json({ count });
}
async function dataInsert(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequest(req);
@ -130,6 +151,10 @@ router.get(
'/data/:orgs/:projectName/:tableName/views/:viewName',
ncMetaAclMw(dataList)
);
router.get(
'/data/:orgs/:projectName/:tableName/views/:viewName/count',
ncMetaAclMw(dataCount)
);
router.post(
'/data/:orgs/:projectName/:tableName/views/:viewName',

69
scripts/sdk/swagger.json

@ -3017,6 +3017,75 @@
}
}
},
"/data/{orgs}/{projectName}/{tableAlias}/views/{viewName}/count": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableAlias",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
}
],
"get": {
"summary": "",
"operationId": "db-view-row-count",
"description": "",
"tags": [
"DB View Row"
],
"parameters": [
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {},
"in": "query",
"name": "nested",
"description": "Query params for nested data"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/data/{tableId}/export/{type}": {
"parameters": [
{

Loading…
Cancel
Save