waibu-maps 2.6.0 → 2.7.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.
@@ -7,10 +7,14 @@ async function controlNewsticker () {
7
7
  return class WmapsControlNewsticker extends WmapsControl {
8
8
  static scripts = [
9
9
  ...super.scripts,
10
- 'waibuExtra.virtual:/acmeticker/acmeticker.min.js',
11
- 'waibuMaps.asset:/js/control-news-ticker.js'
10
+ 'bajo.virtual:/dayjs/dayjs.min.js',
11
+ 'bajo.virtual:/dayjs/plugin/timezone.js',
12
+ 'bajo.virtual:/dayjs/plugin/utc.js',
13
+ 'waibuExtra.virtual:/acmeticker/acmeticker.min.js'
12
14
  ]
13
15
 
16
+ static inlineScript = 'dayjs.extend(dayjs_plugin_timezone); dayjs.extend(dayjs_plugin_utc)'
17
+
14
18
  static css = [
15
19
  ...super.css,
16
20
  'waibuMaps.asset:/css/control-news-ticker.css',
@@ -18,6 +22,13 @@ async function controlNewsticker () {
18
22
  'waibuMaps.asset:/css/acmeticker.css'
19
23
  ]
20
24
 
25
+ static inlineCss = `
26
+ :root { --at-gtr: 0 }
27
+ .at-ticker-label { --at-bg-cl: #f00 }
28
+ .at-ticker-box { font-size: larger }
29
+ .at-ticker-box ul { padding-top: 5px }
30
+ `
31
+
21
32
  constructor (options) {
22
33
  super(options)
23
34
  this.params.noTag = true
@@ -26,29 +37,68 @@ async function controlNewsticker () {
26
37
  build = async () => {
27
38
  const { camelCase } = this.app.lib._
28
39
  const { minify } = this.app.waibuMpa
29
- const { getModel } = this.app.dobo
30
40
 
31
- const model = getModel('CmsPost')
32
- const posts = await model.findRecord({ query: { status: 'PUBLISHED' }, limit: 10 }, { noMagic: true })
33
- console.log(posts)
41
+ this.addBlock('nonReactive', `
42
+ this.posts = []
43
+ `)
34
44
 
35
45
  this.addBlock('reactive', [`
36
46
  async ${prefix}Click (id) {
37
- const item = await wmpa.fetchApi('/cms/post/' + id)
38
- const imgUrl = '/dobo/attachment/cms-post/' + id + '/file/_first?notfound=true'
47
+ const item = this.posts.find(p => p.id === id)
48
+ const att = item._attachments[0]
49
+ let rsc = ''
50
+ if (att) {
51
+ if (att.mimeType.startsWith('video')) {
52
+ rsc = '<iframe style="max-height:600px; min-height:400px; width:100%" frameborder="0" allowfullscreen scrolling="no" allow="camera; microphone; fullscreen" src="' + att.url + '"></iframe>'
53
+ } else {
54
+ rsc = '<img style="max-height:600px" class="img-fluid" src="' + att.url + '">'
55
+ }
56
+ }
39
57
  const html = '<div class="d-flex border-bottom justify-content-center">' +
40
- '<img style="max-height:200px" class="img-fluid" src="/db/attachment/cms-post/' + id + '/file/_first?notfound=true">' +
58
+ rsc +
41
59
  '</div><div class="px-3 py-2"><h5>' + item.title + '</h5>' +
42
60
  item.content.replaceAll('\\n', '<br>') +
43
61
  '</div>'
44
62
 
45
- smaps.showDetails(html)
63
+ smaps.showDetails(html, { title: item.category })
46
64
  const el = document.querySelector('.maplibregl-ctrl-newsticker .content')
47
65
  if (!el) return
48
66
  }
67
+ `, `
68
+ newstickerDt () {
69
+ const el = document.querySelector('.maplibregl-ctrl-newsticker .datetime h5')
70
+ el.textContent = dayjs().tz('Asia/Jakarta').format('HH:mm [WIB]')
71
+ }
72
+ `, `
73
+ async getPosts () {
74
+ if (window.newsticker) window.newsticker.destroy()
75
+ const el = document.querySelector('.maplibregl-ctrl-newsticker .content')
76
+ el.innerHTML = ''
77
+ this.posts = await wmpa.fetchApi('/cms/post', { headers: { 'X-Attachments': 'true' } })
78
+ this.posts.forEach(post => {
79
+ const li = document.createElement('li')
80
+ const a = document.createElement('a')
81
+ a.href = '#'
82
+ a.classList.add('text-decoration-none')
83
+ a.textContent = post.title
84
+ a.addEventListener('click', () => this.${prefix}Click(post.id))
85
+ li.appendChild(a)
86
+ el.appendChild(li)
87
+ })
88
+ window.newsticker = new window.AcmeTicker(el, {
89
+ type: 'vertical',
90
+ direction: 'down',
91
+ speed: 600
92
+ })
93
+ }
49
94
  `])
50
95
 
51
- const content = posts.map(post => `<li><a href="#" @click="${prefix}Click(${post.id})">${post.title}</a></li>`).join('\n')
96
+ this.addBlock('run', `
97
+ this.newstickerDt()
98
+ setInterval(this.newstickerDt, 1000)
99
+ await this.getPosts()
100
+ setInterval(this.getPosts, 5 * 60 * 1000)
101
+ `)
52
102
 
53
103
  const ui = await minify(await this.component.buildSentence(`
54
104
  <c:div class="childmap maplibregl-ctrl-newsticker" x-data>
@@ -56,10 +106,9 @@ async function controlNewsticker () {
56
106
  <c:div class="wrapper maplibregl-ctrl-group">
57
107
  <div class="at-ctnr">
58
108
  <div class="at-ticker at-flx at-pos at-h at-bdr at-bg-cl">
59
- <div class="at-ticker-label at-bg-cl at-cl at-p at-flx-srnk-0">Headlines</div>
109
+ <div class="at-ticker-label at-bg-cl at-cl at-p at-flx-srnk-0 datetime"><h5></h5></div>
60
110
  <c:div class="at-ticker-box at-h at-ovf at-p at-flx-grw-1" margin="start-2">
61
111
  <ul class="content">
62
- ${content}
63
112
  </ul>
64
113
  </c:div>
65
114
  </div>
@@ -1,4 +1,8 @@
1
1
  async function wmapsBase () {
2
+ const controls = ['csrc', 'navigation-control', 'crlr', 'scale-control', 'attribution-control',
3
+ 'centerpos', 'fullscreen-control', 'geolocate-control', 'czbp', 'cmp']
4
+ if (this.app.sumbaCms) controls.push('newsticker')
5
+
2
6
  return class WmapsBase extends this.app.baseClass.MpaWidget {
3
7
  static scripts = [...super.scripts,
4
8
  'waibuMaps.asset:/js/lib/worker-timers.js',
@@ -12,8 +16,7 @@ async function wmapsBase () {
12
16
  'waibuMaps.asset:/css/wmaps.css'
13
17
  ]
14
18
 
15
- static controls = ['csrc', 'navigation-control', 'crlr', 'scale-control', 'attribution-control',
16
- 'centerpos', 'fullscreen-control', 'geolocate-control', 'czbp', 'cmp', 'newsticker']
19
+ static controls = controls
17
20
 
18
21
  async getWmapsTemplate (html, type, defEmpty = '') {
19
22
  const { trim, isEmpty } = this.app.lib._
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-maps",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Maps for Waibu MPA",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-10-25
4
+
5
+ - [2.7.0] Refactor getPosts()
6
+
7
+ ## 2026-10-21
8
+
9
+ - [2.6.1] Bug fix for newsticker condition
10
+
3
11
  ## 2026-10-19
4
12
 
5
13
  - [2.6.0] Add `control-newsticker` widget
@@ -1,5 +0,0 @@
1
- const ticker = new window.AcmeTicker(document.querySelector('.maplibregl-ctrl-newsticker .content'), {
2
- type: 'horizontal',
3
- direction: 'right',
4
- speed: 600
5
- })