"Fossies" - the Fresh Open Source Software Archive

Member "nocodb-0.83.5/packages/nc-gui/components/project/tableTabs/aclTsFileGql.vue" (27 Nov 2021, 10859 Bytes) of package /linux/misc/nocodb-0.83.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) vue.js (beta) source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <!-- eslint-disable -->
    2 <template>
    3   <div>
    4     <v-card style="">
    5       <v-toolbar flat height="42" class="toolbar-border-bottom">
    6         <v-toolbar-title>
    7           <v-breadcrumbs
    8             :items="[{
    9                        text: nodes.env,
   10                        disabled: true,
   11                        href: '#'
   12                      },{
   13                        text: nodes.dbAlias,
   14                        disabled: true,
   15                        href: '#'
   16                      },
   17                      {
   18                        text: nodes.tn + ' (ACL)',
   19                        disabled: true,
   20                        href: '#'
   21                      }]"
   22             divider=">"
   23             small
   24           >
   25             <template #divider>
   26               <v-icon small color="grey lighten-2">
   27                 forward
   28               </v-icon>
   29             </template>
   30           </v-breadcrumbs>
   31         </v-toolbar-title>
   32         <v-spacer />
   33         <x-btn
   34           v-ge="['acl-gql','reload']"
   35           outlined
   36           tooltip="Reload ACL"
   37           color="primary"
   38           small
   39           @click="aclInit"
   40         >
   41           <v-icon small left>
   42             refresh
   43           </v-icon>
   44           Reload
   45         </x-btn>
   46         <x-btn
   47           v-ge="['acl-gql','open-folder']"
   48           tooltip="Open ACL Folder"
   49           icon="mdi-folder-open"
   50           outlined
   51           small
   52           color="primary"
   53           @click="openFolder"
   54         >
   55           Open Folder
   56         </x-btn>
   57         <x-btn
   58           v-ge="['acl-gql','save']"
   59           outlined
   60           tooltip="Save ACL"
   61           color="primary"
   62           class="primary"
   63           small
   64           :disabled="disableSaveButton"
   65           @click="save"
   66         >
   67           <v-icon small left>
   68             save
   69           </v-icon>
   70           Save
   71         </x-btn>
   72       </v-toolbar>
   73 
   74       <v-text-field
   75         v-model="search"
   76         dense
   77         hide-details
   78         class="ma-2"
   79         :placeholder="`Search ${nodes.tn} resolvers`"
   80         prepend-inner-icon="search"
   81         outlined
   82       />
   83 
   84       <v-simple-table v-if="data1" dense>
   85         <thead>
   86           <tr>
   87             <th colspan="2" class="text-center" rowspan="2">
   88               <div class="d-flex justify-center">
   89                 <v-tooltip bottom>
   90                   <template #activator="{ on }">
   91                     <v-checkbox
   92                       v-model="allToggle"
   93                       v-ge="['acl-gql','open-folder']"
   94                       small
   95                       class="mt-1 flex-shrink-1"
   96                       dense
   97                       v-on="on"
   98                     />
   99                   </template>
  100                   <span>{{ allToggle ? 'Disable' : 'Enable' }} all {{ nodes.tn }} resolvers for all roles</span>
  101                 </v-tooltip>
  102                 <span class="title">{{ nodes.tn }} Resolvers</span>
  103               </div>
  104             </th>
  105             <th
  106               v-for="role in roles"
  107               :key="role"
  108               style="border-left: 1px solid grey;border-bottom: 1px solid grey"
  109             >
  110               <div class="d-flex align-center justify-center">
  111                 <span>{{ role }}</span>
  112               </div>
  113             </th>
  114           </tr>
  115           <tr>
  116             <th
  117               v-for="role in roles"
  118               :key="role"
  119               class="pa-1"
  120               style="border-left: 1px solid grey;border-bottom: 1px solid grey"
  121             >
  122               <div class="d-flex justify-center">
  123                 <v-tooltip bottom>
  124                   <template #activator="{ on }">
  125                     <v-checkbox
  126                       v-model="columnToggle[role]"
  127                       v-ge="['acl-gql','open-folder']"
  128                       small
  129                       class="mt-0"
  130                       dense
  131                       v-on="on"
  132                       @change="toggleColumn(role,columnToggle[role])"
  133                     />
  134                   </template>
  135                   <span>
  136                     <span>{{ columnToggle[role] ? 'Disable' : 'Enable' }} all resolvers for {{ role }}</span></span>
  137                 </v-tooltip>
  138               </div>
  139             </th>
  140           </tr>
  141         </thead>
  142         <tbody>
  143           <tr v-for="(resolver,path) in data1" v-show="!search || path.toLowerCase().indexOf(search.toLowerCase()) > -1" :key="path">
  144             <td width="20" class="pl-6 pr-3">
  145               <v-tooltip bottom>
  146                 <template #activator="{ on }">
  147                   <v-checkbox
  148                     v-model="rowToggle[path]"
  149                     v-ge="['acl-gql','open-folder']"
  150                     small
  151                     class="mt-0 ml-3"
  152                     dense
  153                     v-on="on"
  154                     @change="toggleRow(path,rowToggle[path])"
  155                   />
  156                 </template>
  157 
  158                 <span>{{ rowToggle[path] ? 'Disable' : 'Enable' }} this resolver for all roles</span>
  159               </v-tooltip>
  160             </td>
  161             <td class="pl-0">
  162               <v-tooltip bottom>
  163                 <template #activator="{ on }">
  164                   <span v-on="on">{{ path }}</span>
  165                 </template>
  166                 <span>{{ path }}</span>
  167               </v-tooltip>
  168             </td>
  169             <template v-for="(role) in roles">
  170               <td :key="`${path}_${role}`" style="border-left: 1px solid grey" class="pa-1">
  171                 <div class="d-flex justify-center">
  172                   <v-checkbox
  173                     v-model="data1[path][role]"
  174                     v-ge="['acl-gql','open-folder']"
  175                     small
  176                     class="mt-0"
  177                     dense
  178                     @change="toggleCell(path,role,data1[path][role])"
  179                   />
  180                 </div>
  181               </td>
  182             </template>
  183           </tr>
  184         </tbody>
  185       </v-simple-table>
  186 
  187       <v-alert v-else outlined type="info">
  188         Permission file not found
  189       </v-alert>
  190     </v-card>
  191   </div>
  192 </template>
  193 
  194 <script>
  195 import { mapGetters } from 'vuex'
  196 
  197 // const {fs, importFresh, shell, path} = require("electron").remote.require('./libs');
  198 
  199 export default {
  200   name: 'AclTsFileGql',
  201 
  202   props: ['nodes'],
  203   data() {
  204     return {
  205       disableSaveButton: true,
  206       search: '',
  207       policyPath: '',
  208       columnToggle: {},
  209       rowToggle: {},
  210       roles: [
  211         'creator',
  212         'editor',
  213         'guest'
  214       ],
  215       data1: null
  216     }
  217   },
  218   methods: {
  219     openFolder() {
  220       // shell.openItem(path.dirname(this.policyPath))
  221     },
  222     toggleColumn(role, checked) {
  223       for (const [resolver, roles] of Object.entries(this.data1)) {
  224         this.$set(roles, role, checked)
  225         this.toggleCell(resolver, role, checked)
  226       }
  227     },
  228     toggleRow(resolver, checked) {
  229       for (const role in this.data1[resolver]) {
  230         this.$set(this.data1[resolver], role, checked)
  231         this.toggleCell(resolver, role, checked)
  232       }
  233     },
  234     toggleAll(checked) {
  235       this.disableSaveButton = false
  236       for (const path in this.data1) {
  237         this.rowToggle[path] = checked
  238       }
  239       for (const role of this.roles) {
  240         this.columnToggle[role] = checked
  241       }
  242 
  243       for (const roles of Object.values(this.data1)) {
  244         for (const role of this.roles) {
  245           this.$set(roles, role, checked)
  246         }
  247       }
  248     },
  249     toggleCell(resolver, role, checked) {
  250       this.disableSaveButton = false
  251       this.$set(this.columnToggle, role, Object.values(this.data1).some(roles => roles[role]))
  252       this.$set(this.rowToggle, resolver, Object.values(this.data1[resolver]).some(enabled => enabled))
  253     },
  254     initColumnCheckBox() {
  255       for (const role of this.roles) {
  256         this.columnToggle[role] = Object.values(this.data1).some(roles => roles[role])
  257       }
  258     },
  259     initRowCheckBox() {
  260       for (const path in this.data1) {
  261         this.rowToggle[path] = Object.entries(this.data1[path]).filter(([role, v]) => {
  262           if (!this.roles.includes(role)) { this.roles = [...this.roles, role] }
  263           return v
  264         }).length
  265       }
  266     },
  267     async aclInit() {
  268       this.disableSaveButton = true
  269       // this.policyPath = await this.sqlMgr.projectGetGqlPolicyPath({
  270       //   env: this.nodes.env,
  271       //   dbAlias: this.nodes.dbAlias,
  272       //   tn: this.nodes.tn
  273       // });
  274       this.policyPath = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'projectGetGqlPolicyPath', {
  275         env: this.nodes.env,
  276         dbAlias: this.nodes.dbAlias,
  277         tn: this.nodes.tn
  278       }])
  279       try {
  280         console.log(this.policyPath, this.data1)
  281         // this.data1 = JSON.parse(JSON.stringify(await this.sqlMgr.importFresh({path: this.policyPath})));
  282         this.data1 = JSON.parse(JSON.stringify(await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'importFresh', { path: this.policyPath }])))
  283         this.initColumnCheckBox()
  284         this.initRowCheckBox()
  285       } catch (e) {
  286         console.log(e)
  287       }
  288     },
  289     async save() {
  290       try {
  291         // this.sqlMgr.writeFile({path: this.policyPath, data: `module.exports = ${JSON.stringify(this.data1, 0, 2)}`})
  292         await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'writeFile', {
  293           path: this.policyPath,
  294           data: `module.exports = ${JSON.stringify(this.data1, 0, 2)}`
  295         }])
  296         this.disableSaveButton = true
  297         this.$toast.success(`${this.policyPath} updated successfully`).goAway(3000)
  298       } catch (e) {
  299         console.log(e)
  300         this.$toast.error(`${this.policyPath} updating failed`).goAway(3000)
  301       }
  302     }
  303   },
  304   computed: {
  305     ...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
  306     allToggle: {
  307       get() {
  308         return this.data1 && Object.values(this.data1).some(roles => Object.values(roles).some(v => v))
  309       },
  310       set(checked) {
  311         this.toggleAll(checked)
  312       }
  313     }
  314   },
  315   watch: {},
  316   async created() {
  317     await this.aclInit()
  318   }
  319 }
  320 </script>
  321 
  322 <style scoped>
  323 
  324 </style>
  325 <!--
  326 /**
  327  * @copyright Copyright (c) 2021, Xgene Cloud Ltd
  328  *
  329  * @author Naveen MR <oof1lab@gmail.com>
  330  * @author Pranav C Balan <pranavxc@gmail.com>
  331  *
  332  * @license GNU AGPL version 3 or any later version
  333  *
  334  * This program is free software: you can redistribute it and/or modify
  335  * it under the terms of the GNU Affero General Public License as
  336  * published by the Free Software Foundation, either version 3 of the
  337  * License, or (at your option) any later version.
  338  *
  339  * This program is distributed in the hope that it will be useful,
  340  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  341  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  342  * GNU Affero General Public License for more details.
  343  *
  344  * You should have received a copy of the GNU Affero General Public License
  345  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  346  *
  347  */
  348 -->