@websy/websy-designs 0.0.118 → 0.0.122

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.
@@ -8,6 +8,20 @@ const expressSession = require('express-session')
8
8
 
9
9
  module.exports = function (options) {
10
10
  return new Promise((resolve, reject) => {
11
+ const unless = function (middleware) {
12
+ let excludedPaths = ['health']
13
+ if (process.env.EXCLUDED_SESSION_PATHS) {
14
+ excludedPaths = excludedPaths.concat(process.env.EXCLUDED_SESSION_PATHS.split(','))
15
+ }
16
+ return function (req, res, next) {
17
+ if (excludedPaths.indexOf(req.path) !== -1) {
18
+ return next()
19
+ }
20
+ else {
21
+ return middleware(req, res, next)
22
+ }
23
+ }
24
+ }
11
25
  const app = express()
12
26
  app.set('trust proxy', 1)
13
27
  process.env.wdRoot = __dirname
@@ -33,6 +47,9 @@ module.exports = function (options) {
33
47
  next()
34
48
  }
35
49
  app.use(allowCrossDomain)
50
+ app.get('/health', (req, res) => {
51
+ res.json('OK')
52
+ })
36
53
  app.get('/environment', (req, res) => {
37
54
  const env = {}
38
55
  for (let key in process.env) {
@@ -83,26 +100,14 @@ module.exports = function (options) {
83
100
  })
84
101
  }
85
102
  }
86
- app.use(expressSession({
103
+ app.use(unless(expressSession({
87
104
  secret: process.env.SESSION_SECRET,
88
105
  resave: false,
89
106
  saveUninitialized: true,
90
107
  cookie: cookieConfig,
91
108
  name: process.env.COOKIE_NAME,
92
109
  store: store
93
- }))
94
- // app.use(sessionHelper.checkSession(dbHelper))
95
- // app.use(function (req, res, next) {
96
- // console.log('WD MIDDLEWARE')
97
- // console.log(req.session)
98
- // let cookies = {}
99
- // if (typeof req.headers.cookie === 'string') {
100
- // cookies = cookie.parse(req.headers.cookie)
101
- // }
102
- // console.log('cookies')
103
- // console.log(cookies)
104
- // next()
105
- // })
110
+ })))
106
111
  if (options.uses && Array.isArray(options.uses)) {
107
112
  try {
108
113
  options.uses.forEach(u => app.use(u))
@@ -158,8 +158,10 @@ class WebsyLoadingDialog {
158
158
  class WebsyNavigationMenu {
159
159
  constructor (elementId, options) {
160
160
  this.options = Object.assign({}, {
161
+ collapsable: false,
161
162
  orientation: 'horizontal',
162
- parentMap: {}
163
+ parentMap: {},
164
+ childIndentation: 10
163
165
  }, options)
164
166
  if (!elementId) {
165
167
  console.log('No element Id provided for Websy Menu')
@@ -198,15 +200,19 @@ class WebsyNavigationMenu {
198
200
  const el = document.getElementById(this.elementId)
199
201
  if (el) {
200
202
  let html = ``
201
- if (this.options.logo) {
203
+ if (this.options.collapsable === true) {
202
204
  html += `
203
205
  <div id='${this.elementId}_menuIcon' class='websy-menu-icon'>
204
- <svg viewbox="0 0 40 40" width="40" height="40">
205
- <rect x="0" y="0" width="40" height="4" rx="2"></rect>
206
- <rect x="0" y="12" width="40" height="4" rx="2"></rect>
207
- <rect x="0" y="24" width="40" height="4" rx="2"></rect>
206
+ <svg viewbox="0 0 40 40" width="30" height="40">
207
+ <rect x="0" y="0" width="30" height="4" rx="2"></rect>
208
+ <rect x="0" y="12" width="30" height="4" rx="2"></rect>
209
+ <rect x="0" y="24" width="30" height="4" rx="2"></rect>
208
210
  </svg>
209
- </div>
211
+ </div>
212
+ `
213
+ }
214
+ if (this.options.logo) {
215
+ html += `
210
216
  <div
211
217
  class='logo ${(this.options.logo.classes && this.options.logo.classes.join(' ')) || ''}'
212
218
  ${this.options.logo.attributes && this.options.logo.attributes.join(' ')}
@@ -237,15 +243,17 @@ class WebsyNavigationMenu {
237
243
  // update the block to the current item
238
244
  let selected = '' // items[i].default === true ? 'selected' : ''
239
245
  let active = items[i].default === true ? 'active' : ''
240
- let currentBlock = this.normaliseString(items[i].text)
246
+ let currentBlock = this.normaliseString(items[i].text)
247
+ let blockId = items[i].id || `${this.elementId}_${currentBlock}_label`
241
248
  html += `
242
249
  <li class='websy-${this.options.orientation}-list-item'>
243
250
  <div class='websy-menu-header ${items[i].classes && items[i].classes.join(' ')} ${selected} ${active}'
244
- id='${this.elementId}_${currentBlock}_label'
245
- data-id='${currentBlock}'
251
+ id='${blockId}'
252
+ data-id='${currentBlock}'
253
+ data-menu-id='${this.elementId}_${currentBlock}_list'
246
254
  data-popout-id='${level > 1 ? block : currentBlock}'
247
255
  data-text='${items[i].text}'
248
- style='padding-left: ${level * this.options.menuHPadding}px'
256
+ style='padding-left: ${level * this.options.childIndentation}px'
249
257
  ${items[i].attributes && items[i].attributes.join(' ')}
250
258
  >
251
259
  `
@@ -280,6 +288,9 @@ class WebsyNavigationMenu {
280
288
  }
281
289
  html += `</ul>`
282
290
  return html
291
+ }
292
+ toggleOpen () {
293
+
283
294
  }
284
295
  toggleMobileMenu (method) {
285
296
  if (typeof method === 'undefined') {
@@ -978,10 +989,10 @@ class WebsyDropdown {
978
989
  contentEl.classList.remove('on-top')
979
990
  const searchEl = document.getElementById(`${this.elementId}_search`)
980
991
  if (searchEl) {
981
- if (this.options.onCancelSearch) {
982
- this.options.onCancelSearch('')
983
- }
984
- searchEl.value = ''
992
+ if (searchEl.value.length > 0 && this.options.onCancelSearch) {
993
+ this.options.onCancelSearch('')
994
+ searchEl.value = ''
995
+ }
985
996
  }
986
997
  }
987
998
  handleClick (event) {
@@ -2362,19 +2373,60 @@ class WebsyTable {
2362
2373
  bodyHTML += data.map((r, rowIndex) => {
2363
2374
  return '<tr>' + r.map((c, i) => {
2364
2375
  if (this.options.columns[i].show !== false) {
2376
+ let style = ''
2377
+ if (c.style) {
2378
+ style += c.style
2379
+ }
2380
+ if (this.options.columns[i].width) {
2381
+ style += `width: ${this.options.columns[i].width}; `
2382
+ }
2383
+ if (c.backgroundColor) {
2384
+ style += `background-color: ${c.backgroundColor}; `
2385
+ }
2386
+ if (c.color) {
2387
+ style += `color: ${c.color}; `
2388
+ }
2365
2389
  if (this.options.columns[i].showAsLink === true && c.value.trim() !== '') {
2366
2390
  return `
2367
- <td data-row-index='${this.rowCount + rowIndex}' data-col-index='${i}' class='${this.options.columns[i].classes || ''}' ${this.options.columns[i].width ? 'style="width: ' + this.options.columns[i].width + '"' : ''}><a href='${c.value}' target='${this.options.columns[i].openInNewTab === true ? '_blank' : '_self'}'>${this.options.columns[i].linkText || c.value}</a></td>
2391
+ <td
2392
+ data-row-index='${this.rowCount + rowIndex}'
2393
+ data-col-index='${i}'
2394
+ class='${this.options.columns[i].classes || ''}'
2395
+ style='${style}'
2396
+ colspan='${c.colspan || 1}'
2397
+ >
2398
+ <a href='${c.value}' target='${this.options.columns[i].openInNewTab === true ? '_blank' : '_self'}'>${this.options.columns[i].linkText || c.value}</a>
2399
+ </td>
2368
2400
  `
2369
2401
  }
2370
2402
  else if (this.options.columns[i].showAsNavigatorLink === true && c.value.trim() !== '') {
2371
2403
  return `
2372
- <td data-view='${c.value}' data-row-index='${this.rowCount + rowIndex}' data-col-index='${i}' class='trigger-item ${this.options.columns[i].clickable === true ? 'clickable' : ''} ${this.options.columns[i].classes || ''}' ${this.options.columns[i].width ? 'style="width: ' + this.options.columns[i].width + '"' : ''}>${this.options.columns[i].linkText || c.value}</td>
2404
+ <td
2405
+ data-view='${c.value}'
2406
+ data-row-index='${this.rowCount + rowIndex}'
2407
+ data-col-index='${i}'
2408
+ class='trigger-item ${this.options.columns[i].clickable === true ? 'clickable' : ''} ${this.options.columns[i].classes || ''}'
2409
+ style='${style}'
2410
+ colspan='${c.colspan || 1}'
2411
+ >${this.options.columns[i].linkText || c.value}</td>
2373
2412
  `
2374
2413
  }
2375
- else {
2414
+ else {
2415
+ let info = c.value
2416
+ if (this.options.columns[i].showAsImage === true) {
2417
+ c.value = `
2418
+ <img src='${c.value}'>
2419
+ `
2420
+ }
2376
2421
  return `
2377
- <td data-info='${c.value}' data-row-index='${this.rowCount + rowIndex}' data-col-index='${i}' class='${this.options.columns[i].classes || ''}' ${this.options.columns[i].width ? 'style="width: ' + (this.options.columns[i].width || 'auto') + '"' : ''}>${c.value}</td>
2422
+ <td
2423
+ data-info='${info}'
2424
+ data-row-index='${this.rowCount + rowIndex}'
2425
+ data-col-index='${i}'
2426
+ class='${this.options.columns[i].classes || ''}'
2427
+ style='${style}'
2428
+ colspan='${c.colspan || 1}'
2429
+ >${c.value}</td>
2378
2430
  `
2379
2431
  }
2380
2432
  }
@@ -2739,6 +2791,7 @@ this.plotArea = this.svg.append('g')
2739
2791
  this.areaLayer = this.svg.append('g')
2740
2792
  this.lineLayer = this.svg.append('g')
2741
2793
  this.barLayer = this.svg.append('g')
2794
+ this.labelLayer = this.svg.append('g')
2742
2795
  this.symbolLayer = this.svg.append('g')
2743
2796
  this.trackingLineLayer = this.svg.append('g')
2744
2797
  this.trackingLineLayer.append('line').attr('class', 'tracking-line')
@@ -2914,6 +2967,8 @@ else {
2914
2967
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
2915
2968
  this.barLayer
2916
2969
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
2970
+ this.labelLayer
2971
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
2917
2972
  this.symbolLayer
2918
2973
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
2919
2974
  this.trackingLineLayer
@@ -3106,6 +3161,7 @@ else {
3106
3161
  series.color = this.options.colors[index % this.options.colors.length]
3107
3162
  }
3108
3163
  this[`render${series.type || 'bar'}`](series, index)
3164
+ this.renderLabels(series, index)
3109
3165
  })
3110
3166
  }
3111
3167
  }
@@ -3232,6 +3288,76 @@ bars
3232
3288
  return `bar bar_${series.key}`
3233
3289
  })
3234
3290
 
3291
+ }
3292
+ renderLabels (series, index) {
3293
+ /* global series index d3 */
3294
+ let xAxis = 'bottomAxis'
3295
+ let yAxis = 'leftAxis'
3296
+ let that = this
3297
+ if (this.options.orientation === 'horizontal') {
3298
+ xAxis = 'leftAxis'
3299
+ yAxis = 'bottomAxis'
3300
+ }
3301
+ if (this.options.showLabels) {
3302
+ // need to add logic to handle positioning options
3303
+ // e.g. Inside, Outide, Auto (this will also affect the available plot space)
3304
+ // We currently only support 'Auto'
3305
+ let labels = this.labelLayer.selectAll(`.label_${series.key}`).data(series.data)
3306
+ labels
3307
+ .exit()
3308
+ .transition(this.transition)
3309
+ .style('stroke-opacity', 1e-6)
3310
+ .remove()
3311
+ labels
3312
+ .attr('x', getLabelX.bind(this))
3313
+ .attr('y', getLabelY.bind(this))
3314
+ .attr('class', `label_${series.key}`)
3315
+ .style('font-size', `${this.options.labelSize || this.options.fontSize}px`)
3316
+ .transition(this.transition)
3317
+ .text(d => d.y.label || d.y.value)
3318
+
3319
+ labels
3320
+ .enter()
3321
+ .append('text')
3322
+ .attr('class', `label_${series.key}`)
3323
+ .attr('x', getLabelX.bind(this))
3324
+ .attr('y', getLabelY.bind(this))
3325
+ .attr('alignment-baseline', 'central')
3326
+ .attr('text-anchor', this.options.orientation === 'horizontal' ? 'left' : 'middle')
3327
+ .style('font-size', `${this.options.labelSize || this.options.fontSize}px`)
3328
+ .text(d => d.y.label || d.y.value)
3329
+ .each(function (d, i) {
3330
+ if (that.options.orientation === 'horizontal') {
3331
+ if (that.plotWidth - getLabelX.call(that, d) < this.getComputedTextLength()) {
3332
+ this.setAttribute('text-anchor', 'end')
3333
+ this.setAttribute('x', +(this.getAttribute('x')) - 8)
3334
+ }
3335
+ }
3336
+ else {
3337
+ if (that.plotheight - getLabelX.call(that, d) < (that.options.labelSize || that.options.fontSize)) {
3338
+ this.setAttribute('y', +(this.getAttribute('y')) + 8)
3339
+ }
3340
+ }
3341
+ })
3342
+ }
3343
+
3344
+ function getLabelX (d) {
3345
+ if (this.options.orientation === 'horizontal') {
3346
+ return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value) + 4
3347
+ }
3348
+ else {
3349
+ return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
3350
+ }
3351
+ }
3352
+ function getLabelY (d) {
3353
+ if (this.options.orientation === 'horizontal') {
3354
+ return this[xAxis](this.parseX(d.x.value)) + (this[xAxis].bandwidth() / 2)
3355
+ }
3356
+ else {
3357
+ return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value) - 4
3358
+ }
3359
+ }
3360
+
3235
3361
  }
3236
3362
  renderline (series, index) {
3237
3363
  /* global series index d3 */
@@ -3317,7 +3443,7 @@ symbols
3317
3443
  .transition(this.transition)
3318
3444
  .attr('fill', 'white')
3319
3445
  .attr('stroke', series.color)
3320
- .attr('transform', d => { return `translate(${this[xAxis](this.parseX(d.x.value))}, ${this[yAxis](d.y.value)})` })
3446
+ .attr('transform', d => { return `translate(${this[xAxis](this.parseX(d.x.value))}, ${this[yAxis](isNaN(d.y.value) ? 0 : d.y.value)})` })
3321
3447
  // Enter
3322
3448
  symbols.enter()
3323
3449
  .append('path')
@@ -3327,7 +3453,7 @@ symbols.enter()
3327
3453
  .attr('stroke', series.color)
3328
3454
  .attr('class', d => { return `symbol symbol_${series.key}` })
3329
3455
  .attr('transform', d => {
3330
- return `translate(${this[xAxis](this.parseX(d.x.value))}, ${this[yAxis](d.y.value)})`
3456
+ return `translate(${this[xAxis](this.parseX(d.x.value))}, ${this[yAxis](isNaN(d.y.value) ? 0 : d.y.value)})`
3331
3457
  })
3332
3458
 
3333
3459
  }
@@ -3341,8 +3467,10 @@ if (el) {
3341
3467
  .attr('width', this.width)
3342
3468
  .attr('height', this.height)
3343
3469
  // Define the plot height
3470
+ // this.plotWidth = this.width - this.options.margin.left - this.options.margin.right - this.options.margin.axisLeft - this.options.margin.axisRight
3471
+ // this.plotHeight = this.height - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom
3344
3472
  this.plotWidth = this.width - this.options.margin.left - this.options.margin.right - this.options.margin.axisLeft - this.options.margin.axisRight
3345
- this.plotHeight = this.height - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom
3473
+ this.plotHeight = this.height - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom - this.options.margin.axisTop
3346
3474
  // establish the space needed for the various axes
3347
3475
  this.longestRight = 5
3348
3476
  this.longestBottom = 5
@@ -3372,24 +3500,54 @@ if (el) {
3372
3500
  }
3373
3501
  }
3374
3502
  // Translate the layers
3503
+ // this.leftAxisLayer
3504
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3505
+ // this.rightAxisLayer
3506
+ // .attr('transform', `translate(${this.options.margin.left + this.plotWidth + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3507
+ // this.bottomAxisLayer
3508
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.plotHeight})`)
3509
+ // this.plotArea
3510
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3511
+ // this.areaLayer
3512
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3513
+ // this.lineLayer
3514
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3515
+ // this.barLayer
3516
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3517
+ // this.labelLayer
3518
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3519
+ // this.symbolLayer
3520
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3521
+ // this.trackingLineLayer
3522
+ // .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3375
3523
  this.leftAxisLayer
3376
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3524
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3377
3525
  this.rightAxisLayer
3378
- .attr('transform', `translate(${this.options.margin.left + this.plotWidth + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3526
+ .attr('transform', `translate(${this.options.margin.left + this.plotWidth + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3379
3527
  this.bottomAxisLayer
3380
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.plotHeight})`)
3528
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop + this.plotHeight})`)
3529
+ this.leftAxisLabel
3530
+ .attr('transform', `translate(${this.options.margin.left}, ${this.options.margin.top + this.options.margin.axisTop})`)
3531
+ this.rightAxisLabel
3532
+ .attr('transform', `translate(${this.options.margin.left + this.plotWidth + this.options.margin.axisLeft + this.options.margin.axisRight}, ${this.options.margin.top + this.options.margin.axisTop})`)
3533
+ this.bottomAxisLabel
3534
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop + this.plotHeight})`)
3381
3535
  this.plotArea
3382
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3536
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3383
3537
  this.areaLayer
3384
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3538
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3385
3539
  this.lineLayer
3386
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3540
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3387
3541
  this.barLayer
3388
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3542
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3543
+ this.labelLayer
3544
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3389
3545
  this.symbolLayer
3390
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3546
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3391
3547
  this.trackingLineLayer
3392
- .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top})`)
3548
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3549
+ this.eventLayer
3550
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
3393
3551
  }
3394
3552
 
3395
3553
  }