@websy/websy-designs 1.8.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,27 +133,32 @@ class AuthHelper {
133
133
  }
134
134
  checkPermissions (req, res, next) {
135
135
  console.log('hello')
136
- const permissions = {
137
- entities: {
138
- POST: false,
139
- PUT: true,
140
- GET: true,
141
- DELETE: true
142
- },
143
- item: {
144
- POST: true,
145
- PUT: true,
146
- GET: true,
147
- DELETE: true
136
+ if (process.env.USE_PERMISSIONS === 'true' || process.env.USE_PERMISSIONS === true) {
137
+ const permissions = {
138
+ entities: {
139
+ POST: false,
140
+ PUT: true,
141
+ GET: true,
142
+ DELETE: true
143
+ },
144
+ item: {
145
+ POST: true,
146
+ PUT: true,
147
+ GET: true,
148
+ DELETE: true
149
+ }
150
+ }
151
+ if (permissions[req.params.entity] && permissions[req.params.entity][req.method] === true) {
152
+ next()
148
153
  }
149
- }
150
- if (permissions[req.params.entity] && permissions[req.params.entity][req.method] === true) {
151
- next()
154
+ else {
155
+ res.status(403)
156
+ res.json('User does not have permissions to ....')
157
+ }
152
158
  }
153
159
  else {
154
- res.status(403)
155
- res.json('User does not have permissions to ....')
156
- }
160
+ next()
161
+ }
157
162
  }
158
163
  }
159
164
 
@@ -110,6 +110,13 @@ class PGHelper {
110
110
  buildInsert (entity, data, user) {
111
111
  delete data[(this.options.entityConfig[entity] && this.options.entityConfig[entity].idColumn) || 'id']
112
112
  // data.create_user = user
113
+ if (process.env.CREATE_USER_FIELD && process.env.USERID_FIELD && user) {
114
+ data[process.env.CREATE_USER_FIELD] = user[process.env.USERID_FIELD || 'id']
115
+ data[process.env.EDIT_USER_FIELD] = user[process.env.USERID_FIELD || 'id']
116
+ }
117
+ if (process.env.EDIT_DATE_FIELD) {
118
+ data[process.env.EDIT_DATE_FIELD] = (new Date()).toISOString()
119
+ }
113
120
  return `
114
121
  INSERT INTO ${entity} (${Object.keys(data).join(',')})
115
122
  VALUES (${Object.values(data).map(d => (d === null ? `${d}` : `'${d}'`)).join(',')})
@@ -46,7 +46,12 @@ function APIRoutes (dbHelper, authHelper) {
46
46
  router.post('/:entity', authHelper.checkPermissions, (req, res) => {
47
47
  // const sql = dbHelper.buildInsert(req.params.entity, req.body, req.session.passport.user.id)
48
48
  console.log(req.body)
49
- const sql = dbHelper.buildInsert(req.params.entity, req.body)
49
+ console.log(req.session)
50
+ let user
51
+ if (req.session && req.session.user) {
52
+ user = req.session.user
53
+ }
54
+ const sql = dbHelper.buildInsert(req.params.entity, req.body, user)
50
55
  console.log(sql)
51
56
  dbHelper.execute(sql).then(response => res.json(response), err => {
52
57
  res.statusCode = 404
@@ -1,10 +1,7 @@
1
1
  const express = require('express')
2
2
  const bodyParser = require('body-parser')
3
- // const cookie = require('cookie')
4
3
  const cookieParser = require('cookie-parser')
5
4
  const expressSession = require('express-session')
6
- // const sessionHelper = require('./helpers/v1/sessionHelper')
7
- // const DBSession = require(process.env.EXPRESS_SESSION_CONNECT)(expressSession)
8
5
 
9
6
  module.exports = function (options) {
10
7
  return new Promise((resolve, reject) => {
@@ -150,12 +147,15 @@ module.exports = function (options) {
150
147
  // console.log('secure routes', secureRoutes)
151
148
  // console.log('excluded routes', excludedRoutes)
152
149
  // console.log('path', req.path)
153
- // console.log('index of', excludedRoutes.indexOf(req.path))
154
- if (secureRoutes === false && excludedRoutes.indexOf(req.path) !== -1) {
150
+ // console.log('index of', excludedRoutes.indexOf(req.path))
151
+ if (secureRoutes === true) {
152
+ excludedRoutes.push('/resources', '/scripts', '/styles', '/external', '/templates', '/fonts')
153
+ }
154
+ if (secureRoutes === false && excludedRoutes.indexOf('/' + req.path.split('/')[1]) !== -1) {
155
155
  // console.log('in condition A')
156
156
  app.authHelper.isLoggedIn(req, res, next)
157
157
  }
158
- else if (secureRoutes === true && excludedRoutes.indexOf(req.path) === -1) {
158
+ else if (secureRoutes === true && excludedRoutes.indexOf('/' + req.path.split('/')[1]) === -1) {
159
159
  // console.log('in condition B')
160
160
  app.authHelper.isLoggedIn(req, res, next)
161
161
  }
@@ -233,7 +233,7 @@ class ButtonGroup {
233
233
  let activeClass = ''
234
234
  if (this.options.activeItem !== -1) {
235
235
  activeClass = i === this.options.activeItem ? 'active' : 'inactive'
236
- }
236
+ }
237
237
  return `
238
238
  <${this.options.tag} ${(t.attributes || []).join(' ')} data-id="${t.id || t.label}" data-index="${i}" class="websy-button-group-item ${(t.classes || []).join(' ')} ${this.options.style}-style ${activeClass}">${t.label}</${this.options.tag}>
239
239
  `
@@ -1553,24 +1553,47 @@ class WebsyDropdown {
1553
1553
  <div id='${this.elementId}_mask' class='websy-dropdown-mask'></div>
1554
1554
  <div id='${this.elementId}_content' class='websy-dropdown-content'>
1555
1555
  `
1556
- if (this.options.customActions.length > 0) {
1556
+ if (this.options.customActions.length > 0 || this.options.customButtons.length > 0) {
1557
1557
  html += `
1558
1558
  <div class='websy-dropdown-action-container'>
1559
+ `
1560
+ if (this.options.customActions.length > 0) {
1561
+ html += `
1559
1562
  ${this.options.actionsTitle || ''}
1560
1563
  <button class='websy-dropdown-action-button'>
1561
1564
  ${this.options.actionsIcon}
1562
1565
  </button>
1563
- <ul id='${this.elementId}_actionContainer'>
1564
- `
1565
- this.options.customActions.forEach((a, i) => {
1566
+ `
1567
+ }
1568
+ if (this.options.customButtons.length > 0) {
1566
1569
  html += `
1567
- <li class='websy-dropdown-custom-action' data-index='${i}'>${a.label}</li>
1570
+ <div class='websy-dropdown-additional-buttons'>
1568
1571
  `
1569
- })
1570
- html += `
1571
- </ul>
1572
- </div>
1573
- `
1572
+ this.options.customButtons.forEach((b, i) => {
1573
+ html += `
1574
+ <button class='websy-dropdown-custom-button' data-index='${i}'>
1575
+ ${b.label}
1576
+ </button>
1577
+ `
1578
+ })
1579
+ html += `
1580
+ </div>
1581
+ `
1582
+ }
1583
+ if (this.options.customActions.length > 0) {
1584
+ html += `
1585
+ <ul id='${this.elementId}_actionContainer'>
1586
+ `
1587
+ this.options.customActions.forEach((a, i) => {
1588
+ html += `
1589
+ <li class='websy-dropdown-custom-action' data-index='${i}'>${a.label}</li>
1590
+ `
1591
+ })
1592
+ html += `
1593
+ </ul>
1594
+ </div>
1595
+ `
1596
+ }
1574
1597
  }
1575
1598
  if (this.options.disableSearch !== true) {
1576
1599
  html += `
@@ -1590,7 +1613,9 @@ class WebsyDropdown {
1590
1613
  `
1591
1614
  el.innerHTML = html
1592
1615
  const scrollEl = document.getElementById(`${this.elementId}_itemsContainer`)
1593
- scrollEl.addEventListener('scroll', this.handleScroll.bind(this))
1616
+ if (scrollEl) {
1617
+ scrollEl.addEventListener('scroll', this.handleScroll.bind(this))
1618
+ }
1594
1619
  this.render()
1595
1620
  }
1596
1621
  else {
@@ -1638,7 +1663,20 @@ class WebsyDropdown {
1638
1663
  this.options.onClearSelected()
1639
1664
  }
1640
1665
  }
1641
- close () {
1666
+ close () {
1667
+ this.hide()
1668
+ const searchEl = document.getElementById(`${this.elementId}_search`)
1669
+ if (searchEl) {
1670
+ if (searchEl.value.length > 0 && this.options.onCancelSearch) {
1671
+ this.options.onCancelSearch('')
1672
+ searchEl.value = ''
1673
+ }
1674
+ }
1675
+ if (this.options.onClose) {
1676
+ this.options.onClose(this.elementId)
1677
+ }
1678
+ }
1679
+ hide () {
1642
1680
  const maskEl = document.getElementById(`${this.elementId}_mask`)
1643
1681
  const contentEl = document.getElementById(`${this.elementId}_content`)
1644
1682
  const scrollEl = document.getElementById(`${this.elementId}_itemsContainer`)
@@ -1659,17 +1697,7 @@ class WebsyDropdown {
1659
1697
  if (contentEl) {
1660
1698
  contentEl.classList.remove('active')
1661
1699
  contentEl.classList.remove('on-top')
1662
- }
1663
- const searchEl = document.getElementById(`${this.elementId}_search`)
1664
- if (searchEl) {
1665
- if (searchEl.value.length > 0 && this.options.onCancelSearch) {
1666
- this.options.onCancelSearch('')
1667
- searchEl.value = ''
1668
- }
1669
- }
1670
- if (this.options.onClose) {
1671
- this.options.onClose(this.elementId)
1672
- }
1700
+ }
1673
1701
  }
1674
1702
  handleClick (event) {
1675
1703
  if (this.options.disabled === true) {
@@ -1698,6 +1726,12 @@ class WebsyDropdown {
1698
1726
  this.options.customActions[actionIndex].fn()
1699
1727
  }
1700
1728
  }
1729
+ else if (event.target.classList.contains('websy-dropdown-custom-button')) {
1730
+ const actionIndex = +event.target.getAttribute('data-index')
1731
+ if (this.options.customButtons[actionIndex] && this.options.customButtons[actionIndex].fn) {
1732
+ this.options.customButtons[actionIndex].fn()
1733
+ }
1734
+ }
1701
1735
  else if (event.target.classList.contains('websy-dropdown-action-button')) {
1702
1736
  const el = document.getElementById(`${this.elementId}_actionContainer`)
1703
1737
  if (el) {
@@ -1995,7 +2029,7 @@ class WebsyDropdown {
1995
2029
  class WebsyForm {
1996
2030
  constructor (elementId, options) {
1997
2031
  const defaults = {
1998
- submit: { text: 'Save', classes: '' },
2032
+ submit: { text: 'Save', classes: [] },
1999
2033
  useRecaptcha: false,
2000
2034
  clearAfterSave: false,
2001
2035
  fields: [],
@@ -2066,6 +2100,10 @@ class WebsyForm {
2066
2100
  }
2067
2101
  })
2068
2102
  }
2103
+ clear () {
2104
+ const formEl = document.getElementById(`${this.elementId}Form`)
2105
+ formEl.reset()
2106
+ }
2069
2107
  get data () {
2070
2108
  const formEl = document.getElementById(`${this.elementId}Form`)
2071
2109
  const data = {}
@@ -4048,7 +4086,9 @@ class WebsyRouter {
4048
4086
  if (typeof params === 'undefined') {
4049
4087
  return
4050
4088
  }
4051
- this.previousParams = Object.assign({}, this.currentParams)
4089
+ if (reloadView === false) {
4090
+ this.previousParams = Object.assign({}, this.currentParams)
4091
+ }
4052
4092
  const output = {
4053
4093
  path: '',
4054
4094
  items: {}
@@ -4063,7 +4103,9 @@ class WebsyRouter {
4063
4103
  path = this.buildUrlPath(output.items)
4064
4104
  }
4065
4105
  output.path = path
4066
- this.currentParams = output
4106
+ if (reloadView === false) {
4107
+ this.currentParams = output
4108
+ }
4067
4109
  let inputPath = this.currentView
4068
4110
  if (this.options.urlPrefix) {
4069
4111
  inputPath = `/${this.options.urlPrefix}/${inputPath}`
@@ -6027,7 +6069,8 @@ class WebsyTable3 {
6027
6069
  allowPivoting: false,
6028
6070
  searchIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 512 512"><title>ionicons-v5-f</title><path d="M221.09,64A157.09,157.09,0,1,0,378.18,221.09,157.1,157.1,0,0,0,221.09,64Z" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:32px"/><line x1="338.29" y1="338.29" x2="448" y2="448" style="fill:none;stroke:#000;stroke-linecap:round;stroke-miterlimit:10;stroke-width:32px"/></svg>`,
6029
6071
  plusIcon: WebsyDesigns.Icons.PlusFilled,
6030
- minusIcon: WebsyDesigns.Icons.MinusFilled
6072
+ minusIcon: WebsyDesigns.Icons.MinusFilled,
6073
+ disableInternalLoader: false
6031
6074
  }
6032
6075
  this.options = Object.assign({}, DEFAULTS, options)
6033
6076
  this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
@@ -6191,7 +6234,7 @@ class WebsyTable3 {
6191
6234
  bodyHtml += `<td
6192
6235
  class='websy-table-cell ${sizeIndex < this.pinnedColumns ? 'pinned' : 'unpinned'} ${(cell.classes || []).join(' ')} ${(sizingColumns[sizeIndex].classes || []).join(' ')}'
6193
6236
  style='${style}'
6194
- data-info='${cell.value}'
6237
+ data-info='${cell.value.replace(/'/g, '`')}'
6195
6238
  colspan='${cell.colspan || 1}'
6196
6239
  rowspan='${cell.rowspan || 1}'
6197
6240
  data-row-index='${rowIndex}'
@@ -6413,6 +6456,9 @@ class WebsyTable3 {
6413
6456
  columnsForSizing[colIndex].actualWidth = 0
6414
6457
  }
6415
6458
  columnsForSizing[colIndex].actualWidth = Math.min(Math.max(columnsForSizing[colIndex].actualWidth, colSize.width), maxWidth)
6459
+ // if (columnsForSizing[colIndex].width) {
6460
+ // columnsForSizing[colIndex].actualWidth = columnsForSizing[colIndex].width
6461
+ // }
6416
6462
  columnsForSizing[colIndex].cellHeight = colSize.height
6417
6463
  if (colIndex >= this.pinnedColumns) {
6418
6464
  firstNonPinnedColumnWidth = columnsForSizing[colIndex].actualWidth
@@ -7054,7 +7100,9 @@ class WebsyTable3 {
7054
7100
  }
7055
7101
  }
7056
7102
  showLoading (options) {
7057
- this.loadingDialog.show(options)
7103
+ if (this.options.disableInternalLoader !== true) {
7104
+ this.loadingDialog.show(options)
7105
+ }
7058
7106
  }
7059
7107
  }
7060
7108