Browse Source

configure views, sort

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
sync
Raju Udava 3 years ago
parent
commit
5a6088040c
  1. 8
      packages/nocodb/tests/sync/fetchAT.js
  2. 62
      packages/nocodb/tests/sync/sync.js

8
packages/nocodb/tests/sync/fetchAT.js

@ -1,8 +1,12 @@
const axios = require('axios').default; const axios = require('axios').default;
module.exports = async function main(shareId) { module.exports = async function main(shareId, tableId, viewId) {
var Cookie = ""; var Cookie = "";
const hreq = await axios.get(`https://airtable.com/${shareId}`, { let url = `https://airtable.com/${shareId}`
if(tableId && viewId)
url = `https://airtable.com/${shareId}/${tableId}/${viewId}`
const hreq = await axios.get(url, {
"headers": { "headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9", "accept-language": "en-US,en;q=0.9",

62
packages/nocodb/tests/sync/sync.js

@ -138,6 +138,11 @@ async function getAtableSchema() {
return file; return file;
} }
async function getViewData(tblId, viewId) {
let ft = await FetchAT(syncDB.airtable.shareId, tblId, viewId);
return ft.schema?.tableDatas[0]?.viewDatas[0]
}
// base mapping table // base mapping table
let aTblNcTypeMap = { let aTblNcTypeMap = {
foreignKey: UITypes.LinkToAnotherRecord, foreignKey: UITypes.LinkToAnotherRecord,
@ -1018,6 +1023,60 @@ async function nocoCreateProject() {
}); });
} }
async function nocoConfigureGridView(aTblSchema) {
for (let idx = 0; idx < aTblSchema.length; idx++) {
let tblId = (await nc_getTableSchema(aTblSchema[idx].name)).id;
let gridViews = aTblSchema[idx].views.filter(x => x.type === 'grid');
for(let i=0; i<gridViews.length; i++) {
// fetch viewData JSON
let vData = await getViewData(aTblSchema[idx].id, gridViews[i].id)
// retrieve view name & associated NC-ID
let viewName = aTblSchema[idx].views.find(x => x.id === gridViews[i].id)?.name
let viewList = await api.dbView.list(tblId)
let ncViewId = viewList?.list?.find(x => x.tn === viewName)?.id
// create view (default already created)
if(i>0)
await api.dbView.gridCreate(tblId, {title: viewName})
// hide fields
// let hiddenColumns = ["_aTbl_nc_rec_id"]
// // extract other columns hidden in this view
// let hiddenColumnID = vData.columnOrder.filter(x => x.visibility===false)
// for(let j=0; j<hiddenColumnID.length; j++) {
// hiddenColumns.push(aTbl_getColumnName(hiddenColumnID[j].columnId).cn)
// }
// // console.log(`Phase-8 [${String(idx+1).padStart(2, '0')}/${aTblSchema.length}] Hide columns [${idx+1}/${aTblSchema.length}] ${aTblSchema[idx].name}`)
// await nc_hideColumn(aTblSchema[idx].name, viewName, hiddenColumns)
////////////////////////////////////
// configure sort
if(vData?.filters) {
console.log(vData?.filters)
}
// configure filter
if(vData?.lastSortsApplied?.sortSet.length) {
for(let i=0; i<vData.lastSortsApplied.sortSet.length; i++) {
let columnId = (await nc_getColumnSchema(vData.lastSortsApplied.sortSet[i].columnId)).id
await api.dbTableSort.create(ncViewId, {
fk_column_id: columnId,
direction: vData.lastSortsApplied.sortSet[i].ascending?'asc':'dsc'
})
}
}
}
}
}
// start function // start function
async function nc_migrateATbl() { async function nc_migrateATbl() {
@ -1053,6 +1112,9 @@ async function nc_migrateATbl() {
// hide-fields // hide-fields
await nocoReconfigureFields(aTblSchema); await nocoReconfigureFields(aTblSchema);
// configure grid views
await nocoConfigureGridView(aTblSchema)
if(process_aTblData) { if(process_aTblData) {
// await nc_DumpTableSchema(); // await nc_DumpTableSchema();
let ncTblList = await api.dbTable.list(ncCreatedProjectSchema.id); let ncTblList = await api.dbTable.list(ncCreatedProjectSchema.id);

Loading…
Cancel
Save