Bladeren bron

Hide currency

Alan Colon 7 jaren geleden
bovenliggende
commit
d14ec1d718
4 gewijzigde bestanden met toevoegingen van 60 en 9 verwijderingen
  1. 35 5
      app/components/staff-member-pages.js
  2. 8 0
      app/services/api.js
  3. 4 4
      lib/database/initialize.js
  4. 13 0
      lib/database/staff-member.js

+ 35 - 5
app/components/staff-member-pages.js

@@ -1,4 +1,5 @@
 const { pages } = require('@alancnet/material-framework/app/crud')
 const { pages } = require('@alancnet/material-framework/app/crud')
+const { dollarIcon } = require('../assets')
 
 
 pages({
 pages({
   camelName: 'staffMember',
   camelName: 'staffMember',
@@ -35,26 +36,55 @@ pages({
     {
     {
       inList: false,
       inList: false,
       camelName: 'wage',
       camelName: 'wage',
-      type: 'currency'
+      type: 'currency',
+      field: html`
+        <md-input-container flex ng-if="$ctrl.api.claims['INCOME_' + $ctrl.laborCategoryKey + '_VIEW']">
+          <label>Wage</label>
+          <input type="number" step="0.01" ng-model="model.wage" />
+          <md-icon md-svg-src="${dollarIcon}"></md-icon>
+        </md-input-container>
+      `
     },
     },
     {
     {
       inList: false,
       inList: false,
       camelName: 'salary',
       camelName: 'salary',
-      type: 'currency'
+      type: 'currency',
+      field: html`
+        <md-input-container flex ng-if="$ctrl.api.claims['INCOME_' + $ctrl.laborCategoryKey + '_VIEW']">
+          <label>Salary</label>
+          <input type="number" step="0.01" ng-model="model.salary" />
+          <md-icon md-svg-src="${dollarIcon}"></md-icon>
+        </md-input-container>
+      `
     }
     }
   ],
   ],
+  controllers: {
+    details: function() {
+      this.loadingPromise.then(async () => {
+        const cats = await this.api.laborCategoryDictionary()
+        const unwatch = this.$scope.$watch('model.laborCategoryId', (laborCategoryId) => {
+          if (laborCategoryId) {
+            this.laborCategoryKey = cats[laborCategoryId].key
+          } else {
+            this.laborCategoryKey = null
+          }
+        })
+        this.$scope.$on('$destroy', unwatch)
+      })
+    }
+  },
   layout: [
   layout: [
     {
     {
       section: null,
       section: null,
       rows: [
       rows: [
-        [ 'name', 'title', 'terminalId' ],
-        [ 'wage', 'salary' ]
+        [ 'name', 'title', ],
+        [ 'laborCategoryId', 'terminalId' ]
       ]
       ]
     },
     },
     {
     {
       section: 'Staffing information',
       section: 'Staffing information',
       rows: [
       rows: [
-        [ 'laborCategoryId', 'staffingAgencyId' ]
+        [ 'wage', 'salary', 'staffingAgencyId' ]
       ]
       ]
     }
     }
   ]
   ]

+ 8 - 0
app/services/api.js

@@ -30,4 +30,12 @@ app.run(function(api) {
     _.fromPairs(clients.map(sm => [sm.id, sm]))
     _.fromPairs(clients.map(sm => [sm.id, sm]))
   ))
   ))
 
 
+  let laborCategories = null
+  api.laborCategories = () => laborCategories || (laborCategories = api.get('/api/labor-categories'))
+
+  let laborCategoryDictionary= null
+  api.laborCategoryDictionary = () => laborCategoryDictionary || (laborCategoryDictionary = api.laborCategories().then(laborCategories =>
+    _.fromPairs(laborCategories.map(lc => [lc.id, lc]))
+  ))
+
 })
 })

+ 4 - 4
lib/database/initialize.js

@@ -84,10 +84,10 @@ const roles = [
       'USER_READ',
       'USER_READ',
       'USER_UNDELETE',
       'USER_UNDELETE',
       'USER_UPDATE',
       'USER_UPDATE',
-      'VIEW_INCOME_ADMIN',
-      'VIEW_INCOME_DELIVERY',
-      'VIEW_INCOME_OPS',
-      'VIEW_INCOME_WAREHOUSE',
+      'INCOME_ADMIN_VIEW',
+      'INCOME_DELIVERY_VIEW',
+      'INCOME_OPS_VIEW',
+      'INCOME_WAREHOUSE_VIEW',
       'VIEW_TERMINAL_LAS',
       'VIEW_TERMINAL_LAS',
       'VIEW_TERMINAL_LAX',
       'VIEW_TERMINAL_LAX',
       'VIEW_TERMINAL_PHX',
       'VIEW_TERMINAL_PHX',

+ 13 - 0
lib/database/staff-member.js

@@ -25,4 +25,17 @@ const StaffMember = sequelize.define('staffMember', {
   ]
   ]
 })
 })
 
 
+StaffMember.prototype.sanitize = async function(req) {
+  const record = this.toJSON()
+  const LaborCategory = sequelize.models.laborCategory
+  if (this.laborCategoryId) {
+    const {key} = await LaborCategory.findOne({where: {id: this.laborCategoryId}})
+    if (!req.claims[`INCOME_${key}_VIEW`]) {
+      delete record.wage
+      delete record.salary
+    }
+  }
+  return record
+}
+
 module.exports = StaffMember
 module.exports = StaffMember