@websy/websy-designs 1.8.2 → 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
@@ -147,12 +147,15 @@ module.exports = function (options) {
147
147
  // console.log('secure routes', secureRoutes)
148
148
  // console.log('excluded routes', excludedRoutes)
149
149
  // console.log('path', req.path)
150
- // console.log('index of', excludedRoutes.indexOf(req.path))
151
- 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) {
152
155
  // console.log('in condition A')
153
156
  app.authHelper.isLoggedIn(req, res, next)
154
157
  }
155
- else if (secureRoutes === true && excludedRoutes.indexOf(req.path) === -1) {
158
+ else if (secureRoutes === true && excludedRoutes.indexOf('/' + req.path.split('/')[1]) === -1) {
156
159
  // console.log('in condition B')
157
160
  app.authHelper.isLoggedIn(req, res, next)
158
161
  }
@@ -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 += `
@@ -1640,7 +1663,20 @@ class WebsyDropdown {
1640
1663
  this.options.onClearSelected()
1641
1664
  }
1642
1665
  }
1643
- 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 () {
1644
1680
  const maskEl = document.getElementById(`${this.elementId}_mask`)
1645
1681
  const contentEl = document.getElementById(`${this.elementId}_content`)
1646
1682
  const scrollEl = document.getElementById(`${this.elementId}_itemsContainer`)
@@ -1661,17 +1697,7 @@ class WebsyDropdown {
1661
1697
  if (contentEl) {
1662
1698
  contentEl.classList.remove('active')
1663
1699
  contentEl.classList.remove('on-top')
1664
- }
1665
- const searchEl = document.getElementById(`${this.elementId}_search`)
1666
- if (searchEl) {
1667
- if (searchEl.value.length > 0 && this.options.onCancelSearch) {
1668
- this.options.onCancelSearch('')
1669
- searchEl.value = ''
1670
- }
1671
- }
1672
- if (this.options.onClose) {
1673
- this.options.onClose(this.elementId)
1674
- }
1700
+ }
1675
1701
  }
1676
1702
  handleClick (event) {
1677
1703
  if (this.options.disabled === true) {
@@ -1700,6 +1726,12 @@ class WebsyDropdown {
1700
1726
  this.options.customActions[actionIndex].fn()
1701
1727
  }
1702
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
+ }
1703
1735
  else if (event.target.classList.contains('websy-dropdown-action-button')) {
1704
1736
  const el = document.getElementById(`${this.elementId}_actionContainer`)
1705
1737
  if (el) {
@@ -1997,7 +2029,7 @@ class WebsyDropdown {
1997
2029
  class WebsyForm {
1998
2030
  constructor (elementId, options) {
1999
2031
  const defaults = {
2000
- submit: { text: 'Save', classes: '' },
2032
+ submit: { text: 'Save', classes: [] },
2001
2033
  useRecaptcha: false,
2002
2034
  clearAfterSave: false,
2003
2035
  fields: [],
@@ -2068,6 +2100,10 @@ class WebsyForm {
2068
2100
  }
2069
2101
  })
2070
2102
  }
2103
+ clear () {
2104
+ const formEl = document.getElementById(`${this.elementId}Form`)
2105
+ formEl.reset()
2106
+ }
2071
2107
  get data () {
2072
2108
  const formEl = document.getElementById(`${this.elementId}Form`)
2073
2109
  const data = {}
@@ -4050,7 +4086,9 @@ class WebsyRouter {
4050
4086
  if (typeof params === 'undefined') {
4051
4087
  return
4052
4088
  }
4053
- this.previousParams = Object.assign({}, this.currentParams)
4089
+ if (reloadView === false) {
4090
+ this.previousParams = Object.assign({}, this.currentParams)
4091
+ }
4054
4092
  const output = {
4055
4093
  path: '',
4056
4094
  items: {}
@@ -4065,7 +4103,9 @@ class WebsyRouter {
4065
4103
  path = this.buildUrlPath(output.items)
4066
4104
  }
4067
4105
  output.path = path
4068
- this.currentParams = output
4106
+ if (reloadView === false) {
4107
+ this.currentParams = output
4108
+ }
4069
4109
  let inputPath = this.currentView
4070
4110
  if (this.options.urlPrefix) {
4071
4111
  inputPath = `/${this.options.urlPrefix}/${inputPath}`
@@ -6029,7 +6069,8 @@ class WebsyTable3 {
6029
6069
  allowPivoting: false,
6030
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>`,
6031
6071
  plusIcon: WebsyDesigns.Icons.PlusFilled,
6032
- minusIcon: WebsyDesigns.Icons.MinusFilled
6072
+ minusIcon: WebsyDesigns.Icons.MinusFilled,
6073
+ disableInternalLoader: false
6033
6074
  }
6034
6075
  this.options = Object.assign({}, DEFAULTS, options)
6035
6076
  this.isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
@@ -7059,7 +7100,9 @@ class WebsyTable3 {
7059
7100
  }
7060
7101
  }
7061
7102
  showLoading (options) {
7062
- this.loadingDialog.show(options)
7103
+ if (this.options.disableInternalLoader !== true) {
7104
+ this.loadingDialog.show(options)
7105
+ }
7063
7106
  }
7064
7107
  }
7065
7108
 
@@ -1549,12 +1549,25 @@ var WebsyDropdown = /*#__PURE__*/function () {
1549
1549
  html += "<div class='clear'>".concat(this.options.clearIcon, "</div>");
1550
1550
  }
1551
1551
  html += " \n </div>\n <div id='".concat(this.elementId, "_mask' class='websy-dropdown-mask'></div>\n <div id='").concat(this.elementId, "_content' class='websy-dropdown-content'>\n ");
1552
- if (this.options.customActions.length > 0) {
1553
- html += "\n <div class='websy-dropdown-action-container'>\n ".concat(this.options.actionsTitle || '', "\n <button class='websy-dropdown-action-button'>\n ").concat(this.options.actionsIcon, "\n </button>\n <ul id='").concat(this.elementId, "_actionContainer'>\n ");
1554
- this.options.customActions.forEach(function (a, i) {
1555
- html += "\n <li class='websy-dropdown-custom-action' data-index='".concat(i, "'>").concat(a.label, "</li>\n ");
1556
- });
1557
- html += "\n </ul>\n </div>\n ";
1552
+ if (this.options.customActions.length > 0 || this.options.customButtons.length > 0) {
1553
+ html += "\n <div class='websy-dropdown-action-container'>\n ";
1554
+ if (this.options.customActions.length > 0) {
1555
+ html += "\n ".concat(this.options.actionsTitle || '', "\n <button class='websy-dropdown-action-button'>\n ").concat(this.options.actionsIcon, "\n </button>\n ");
1556
+ }
1557
+ if (this.options.customButtons.length > 0) {
1558
+ html += "\n <div class='websy-dropdown-additional-buttons'>\n ";
1559
+ this.options.customButtons.forEach(function (b, i) {
1560
+ html += "\n <button class='websy-dropdown-custom-button' data-index='".concat(i, "'>\n ").concat(b.label, "\n </button>\n ");
1561
+ });
1562
+ html += "\n </div>\n ";
1563
+ }
1564
+ if (this.options.customActions.length > 0) {
1565
+ html += " \n <ul id='".concat(this.elementId, "_actionContainer'>\n ");
1566
+ this.options.customActions.forEach(function (a, i) {
1567
+ html += "\n <li class='websy-dropdown-custom-action' data-index='".concat(i, "'>").concat(a.label, "</li>\n ");
1568
+ });
1569
+ html += "\n </ul>\n </div>\n ";
1570
+ }
1558
1571
  }
1559
1572
  if (this.options.disableSearch !== true) {
1560
1573
  html += "\n <div class='websy-dropdown-search-container'>\n <input id='".concat(this.elementId, "_search' class='websy-dropdown-search' placeholder='").concat(this.options.searchPlaceholder || 'Search', "'>\n </div>\n ");
@@ -1621,6 +1634,21 @@ var WebsyDropdown = /*#__PURE__*/function () {
1621
1634
  }, {
1622
1635
  key: "close",
1623
1636
  value: function close() {
1637
+ this.hide();
1638
+ var searchEl = document.getElementById("".concat(this.elementId, "_search"));
1639
+ if (searchEl) {
1640
+ if (searchEl.value.length > 0 && this.options.onCancelSearch) {
1641
+ this.options.onCancelSearch('');
1642
+ searchEl.value = '';
1643
+ }
1644
+ }
1645
+ if (this.options.onClose) {
1646
+ this.options.onClose(this.elementId);
1647
+ }
1648
+ }
1649
+ }, {
1650
+ key: "hide",
1651
+ value: function hide() {
1624
1652
  var maskEl = document.getElementById("".concat(this.elementId, "_mask"));
1625
1653
  var contentEl = document.getElementById("".concat(this.elementId, "_content"));
1626
1654
  var scrollEl = document.getElementById("".concat(this.elementId, "_itemsContainer"));
@@ -1642,16 +1670,6 @@ var WebsyDropdown = /*#__PURE__*/function () {
1642
1670
  contentEl.classList.remove('active');
1643
1671
  contentEl.classList.remove('on-top');
1644
1672
  }
1645
- var searchEl = document.getElementById("".concat(this.elementId, "_search"));
1646
- if (searchEl) {
1647
- if (searchEl.value.length > 0 && this.options.onCancelSearch) {
1648
- this.options.onCancelSearch('');
1649
- searchEl.value = '';
1650
- }
1651
- }
1652
- if (this.options.onClose) {
1653
- this.options.onClose(this.elementId);
1654
- }
1655
1673
  }
1656
1674
  }, {
1657
1675
  key: "handleClick",
@@ -1676,6 +1694,11 @@ var WebsyDropdown = /*#__PURE__*/function () {
1676
1694
  if (this.options.customActions[actionIndex] && this.options.customActions[actionIndex].fn) {
1677
1695
  this.options.customActions[actionIndex].fn();
1678
1696
  }
1697
+ } else if (event.target.classList.contains('websy-dropdown-custom-button')) {
1698
+ var _actionIndex = +event.target.getAttribute('data-index');
1699
+ if (this.options.customButtons[_actionIndex] && this.options.customButtons[_actionIndex].fn) {
1700
+ this.options.customButtons[_actionIndex].fn();
1701
+ }
1679
1702
  } else if (event.target.classList.contains('websy-dropdown-action-button')) {
1680
1703
  var _el = document.getElementById("".concat(this.elementId, "_actionContainer"));
1681
1704
  if (_el) {
@@ -1997,7 +2020,7 @@ var WebsyForm = /*#__PURE__*/function () {
1997
2020
  var defaults = {
1998
2021
  submit: {
1999
2022
  text: 'Save',
2000
- classes: ''
2023
+ classes: []
2001
2024
  },
2002
2025
  useRecaptcha: false,
2003
2026
  clearAfterSave: false,
@@ -2077,6 +2100,12 @@ var WebsyForm = /*#__PURE__*/function () {
2077
2100
  }
2078
2101
  });
2079
2102
  }
2103
+ }, {
2104
+ key: "clear",
2105
+ value: function clear() {
2106
+ var formEl = document.getElementById("".concat(this.elementId, "Form"));
2107
+ formEl.reset();
2108
+ }
2080
2109
  }, {
2081
2110
  key: "data",
2082
2111
  get: function get() {
@@ -3842,7 +3871,9 @@ var WebsyRouter = /*#__PURE__*/function () {
3842
3871
  if (typeof params === 'undefined') {
3843
3872
  return;
3844
3873
  }
3845
- this.previousParams = _extends({}, this.currentParams);
3874
+ if (reloadView === false) {
3875
+ this.previousParams = _extends({}, this.currentParams);
3876
+ }
3846
3877
  var output = {
3847
3878
  path: '',
3848
3879
  items: {}
@@ -3856,7 +3887,9 @@ var WebsyRouter = /*#__PURE__*/function () {
3856
3887
  path = this.buildUrlPath(output.items);
3857
3888
  }
3858
3889
  output.path = path;
3859
- this.currentParams = output;
3890
+ if (reloadView === false) {
3891
+ this.currentParams = output;
3892
+ }
3860
3893
  var inputPath = this.currentView;
3861
3894
  if (this.options.urlPrefix) {
3862
3895
  inputPath = "/".concat(this.options.urlPrefix, "/").concat(inputPath);
@@ -5772,7 +5805,8 @@ var WebsyTable3 = /*#__PURE__*/function () {
5772
5805
  allowPivoting: false,
5773
5806
  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>",
5774
5807
  plusIcon: WebsyDesigns.Icons.PlusFilled,
5775
- minusIcon: WebsyDesigns.Icons.MinusFilled
5808
+ minusIcon: WebsyDesigns.Icons.MinusFilled,
5809
+ disableInternalLoader: false
5776
5810
  };
5777
5811
  this.options = _extends({}, DEFAULTS, options);
5778
5812
  this.isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
@@ -6777,7 +6811,9 @@ var WebsyTable3 = /*#__PURE__*/function () {
6777
6811
  }, {
6778
6812
  key: "showLoading",
6779
6813
  value: function showLoading(options) {
6780
- this.loadingDialog.show(options);
6814
+ if (this.options.disableInternalLoader !== true) {
6815
+ this.loadingDialog.show(options);
6816
+ }
6781
6817
  }
6782
6818
  }]);
6783
6819
  return WebsyTable3;