Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
vacuum.ui.js156 linesDownload Raw Back to js
1import gettext from 'sources/gettext';2import BaseUISchema from 'sources/SchemaView/base_schema.ui';3import { getNodeAjaxOptions } from '../../../../static/js/node_ajax';4 5export function getNodeVacuumSettingsSchema(nodeObj, treeNodeInfo, itemNodeData) {6  let tableVacuumRows = ()=>getNodeAjaxOptions('get_table_vacuum', nodeObj, treeNodeInfo, itemNodeData, {noCache: true});7  let toastTableVacuumRows = ()=>getNodeAjaxOptions('get_toast_table_vacuum', nodeObj, treeNodeInfo, itemNodeData, {noCache: true});8  return new VacuumSettingsSchema(tableVacuumRows, toastTableVacuumRows, treeNodeInfo);9}10export class VacuumTableSchema extends BaseUISchema {11  constructor(valueDep) {12    super();13    this.valueDep = valueDep;14  }15 16  get baseFields() {17    let obj = this;18 19    return [20      {21        id: 'label', name: 'label', label: gettext('Label'), cell: '',22      },23      {24        id: 'value', name: 'value', label: gettext('Value'),25        type: 'text', deps: [[this.valueDep]],26        editable: function() {27          return obj.top.sessData[this.valueDep];28        },29        cell: (state)=>{30          switch(state.column_type) {31          case 'integer':32            return {cell: 'int'};33          case 'number':34            return {cell: 'numeric', controlProps: {decimals: 5}};35          case 'string':36            return {cell: 'text'};37          default:38            return {cell: ''};39          }40        }41      },42      {43        id: 'setting', name: 'setting', label: gettext('Default'), cell: '',44      },45    ];46  }47}48 49export default class VacuumSettingsSchema extends BaseUISchema {50  constructor(tableVars, toastTableVars, nodeInfo) {51    super({52      vacuum_table: [],53      vacuum_toast: [],54    });55    this.tableVars = tableVars;56    this.toastTableVars = toastTableVars;57    this.nodeInfo = nodeInfo;58 59    this.vacuumTableObj = new VacuumTableSchema('autovacuum_custom');60    this.vacuumToastTableObj = new VacuumTableSchema('toast_autovacuum');61  }62 63  get baseFields() {64    let obj = this;65    return [{66      id: 'autovacuum_custom', label: gettext('Custom auto-vacuum?'),67      group: gettext('Table'), mode: ['edit', 'create'], skipChange: true,68      type: 'switch', disabled: function(state) {69        if(state.is_partitioned) {70          return true;71        }72        // If table is partitioned table then disabled it.73        if(state.top && state.is_partitioned) {74          return true;75        }76 77        return !obj.inCatalog;78      },79      depChange(state) {80        if(state.is_partitioned) {81          return {autovacuum_custom: false};82        }83      }84    },85    {86      id: 'autovacuum_enabled', label: gettext('Autovacuum Enabled?'),87      group: gettext('Table'), mode: ['edit', 'create'], type: 'toggle',88      options: [89        {'label': gettext('Not set'), 'value': 'x'},90        {'label': gettext('Yes'), 'value': 't'},91        {'label': gettext('No'), 'value': 'f'},92      ],93      deps: ['autovacuum_custom'],94      disabled: function(state) {95        return !(obj.inCatalog && state.autovacuum_custom);96      },97      depChange: function(state) {98        if(obj.inCatalog && state.autovacuum_custom) {99          return;100        }101        return {autovacuum_enabled: 'x'};102      },103    },104    {105      id: 'vacuum_table', label: '', editable: false, type: 'collection',106      canEdit: false, canAdd: false, canDelete: false, group: gettext('Table'),107      fixedRows: this.tableVars,108      schema: this.vacuumTableObj,109      mode: ['edit', 'create'],110    },111    {112      id: 'toast_autovacuum', label: gettext('Custom auto-vacuum?'),113      group: gettext('TOAST table'), mode: ['edit', 'create'],114      type: 'switch',115      disabled: function(state) {116        // We need to check additional condition to toggle enable/disable117        // for table auto-vacuum118        return !(obj.inCatalog && (obj.top.isNew() || state.hastoasttable));119      }120    },121    {122      id: 'toast_autovacuum_enabled', label: gettext('Autovacuum Enabled?'),123      group: gettext('TOAST table'), mode: ['edit', 'create'],124      type: 'toggle',125      options: [126        {'label': gettext('Not set'), 'value': 'x'},127        {'label': gettext('Yes'), 'value': 't'},128        {'label': gettext('No'), 'value': 'f'},129      ],130      deps:['toast_autovacuum'],131      disabled: function(state) {132        return !(obj.inCatalog && state.toast_autovacuum);133      },134      depChange: function(state) {135        if(obj.inCatalog && state.toast_autovacuum) {136          return;137        }138        if(obj.isNew() || state.hastoasttable) {139          return {toast_autovacuum_enabled: 'x'};140        }141      },142    },143    {144      id: 'vacuum_toast', label: '',145      type: 'collection',146      fixedRows: this.toastTableVars,147      editable: function(state) {148        return obj.isNew(state);149      },150      canEdit: false, canAdd: false, canDelete: false, group: gettext('TOAST table'),151      schema: this.vacuumToastTableObj,152      mode: ['properties', 'edit', 'create'], deps: ['toast_autovacuum'],153    }];154  }155}156 
codekingpro/portable-devtools · Team Ai