@sgcloud-sgsistemas/base 1.0.30 → 1.0.31

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgcloud-sgsistemas/base",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "Base para os sistemas da mobiage",
5
5
  "repository": {
6
6
  "type": "private",
@@ -1,10 +1,48 @@
1
1
  <div class="sg" hotbar
2
2
  ng-class="{
3
- 'opened':vm.open || vm.openedIndexSub,
3
+ 'opened':vm.open || vm.openedIndexSub || vm.openedIndexSub == 0,
4
4
  'force-hide':vm.forceHide,
5
5
  're-open':vm.reopen,
6
6
  'hover':vm.openedIndexSub == undefined,
7
7
  }">
8
- <modules ng-transclude="module" ng-if="!vm.ngifHide">
8
+ <modules ng-if="!vm.ngifHide">
9
+ <module main="true" ng-click="vm.onClickMain()">
10
+ <div>
11
+ <i class="{{vm.config.quickMenu.icon || 'fas fa-times'}}"></i>
12
+ <label>{{vm.config.quickMenu.buttonText}}</label>
13
+ </div>
14
+ </module>
15
+ <module main="true"
16
+ ng-repeat="module in vm.config.quickMenu.links track by $index"
17
+ ng-hide="vm.forceHide"
18
+ ng-class="{'hidden':!vm.config.quickMenu.open}"
19
+ ng-click="vm.onSubModuleSelected(module, true, $event)">
20
+ <div >
21
+ <i class="{{module.icon}}"></i>
22
+ <label>{{module.label}}</label>
23
+ </div>
24
+ </module>
25
+ <module ng-repeat="module in vm.config.structure"
26
+ ng-if="module.label && module.children"
27
+ ng-hide="vm.forceHide"
28
+ ng-class="{'hidden':vm.config.quickMenu.open, 'force-open-sub': vm.openedIndexSub == $index}"
29
+ ng-click="vm.onClickModule($index)"
30
+ id="sg-hotbar-module-{{$index}}">
31
+ <div>
32
+ <i ng-if="module.icon && module.icon != ''"
33
+ class="{{module.icon}}">
34
+ </i>
35
+ <label>{{module.label}}</label>
36
+ </div>
37
+ <sub-module ng-style="::vm.getSubModuleStyle($index)"
38
+ id="sg-hotbar-sub-modules-{{$index}}">
39
+ <div ng-if="!subModule.hide"
40
+ ng-repeat="subModule in module.children"
41
+ ng-click="vm.onSubModuleSelected(subModule, false, $event)">
42
+ <i class="{{subModule.icon}}"></i>
43
+ <label>{{subModule.label}}</label>
44
+ </div>
45
+ </sub-module>
46
+ </module>
9
47
  </modules>
10
48
  </div>
@@ -139,7 +139,6 @@ hotbar {
139
139
  position: absolute;
140
140
  z-index: -1;
141
141
  overflow-y: scroll;
142
- transform: translateY(-40%);
143
142
 
144
143
  >* {
145
144
  overflow: hidden;
@@ -2,7 +2,7 @@ import $ from 'jquery';
2
2
  import { MbSidemenuService } from './../../services/sidemenu-service';
3
3
  import template from './hotbar.html';
4
4
  import './hotbar.scss';
5
- import { $Interval, $Scope, $Timeout, GenericFunction } from './interface/angular-interface/angular';
5
+ import { $Interval, $Scope, $Timeout, CssInterface, GenericFunction } from './interface/angular-interface/angular';
6
6
  import { Config, SubModule } from './interface/config';
7
7
 
8
8
  class HotbarController {
@@ -42,9 +42,7 @@ class HotbarController {
42
42
  this.$scope.$on('$destroy', (): void => this.$onDestroy())
43
43
  this.mbSidemenuService.sideMenu = this.sgElement
44
44
  this.__initWatchers()
45
- this.$rootScope.$on("reloadHotBar", ()=>{
46
- this.__updateHotbar()
47
- });
45
+ this.$rootScope.$on("reloadHotBar", ()=> this.__updateHotbar() );
48
46
  }
49
47
 
50
48
  private __unWatch(watcher?: Function): void {
@@ -65,7 +63,6 @@ class HotbarController {
65
63
 
66
64
  private __onClick: (ev: MouseEvent)=> void = (ev: MouseEvent): void => {
67
65
  if (this.sgElement.find(ev.target).length == 0 && this.openedIndexSub != undefined) {
68
- $(this.modules[this.openedIndexSub]).removeClass('force-open-sub')
69
66
  this.openedIndexSub = undefined
70
67
  try{
71
68
  this.$scope.$digest()
@@ -84,41 +81,47 @@ class HotbarController {
84
81
  if (this.subModules) {
85
82
  this.subModules.each((index: number, subModuleElement: Element): void => {
86
83
  let subModule: JQuery = $(subModuleElement)
84
+ const cssObj = this.getSubModuleStyleFromElement(subModule)
85
+ subModule.css(cssObj)
86
+ })
87
+ }
88
+ }
87
89
 
88
- const borderRadius = 10
89
- const hotbarHeight: number = this.sgElement.height() - (borderRadius * 4)
90
+ public getSubModuleStyle($index: number): CssInterface {
91
+ const subModule = $(this.$element.find(`#sg-hotbar-sub-modules-${$index}`)[0])
92
+ return this.getSubModuleStyleFromElement(subModule);
93
+ }
90
94
 
91
- let cssObj: any = {
92
- 'max-height': `${hotbarHeight}px`,
93
- 'transform': '',
94
- 'top': '',
95
- 'bottom': '',
96
- }
95
+ private getSubModuleStyleFromElement(subModule: any): CssInterface {
96
+ const borderRadius = 10;
97
+ const hotbarHeight: number = this.sgElement.height() - (borderRadius * 4);
97
98
 
98
- const rectSG: DOMRect = this.sgElement[0].getBoundingClientRect()
99
- const rectModule: DOMRect = subModule.parent()[0].getBoundingClientRect()
100
- const rectSubModule: DOMRect = subModule[0].getBoundingClientRect()
101
- const scrollTopPosition: number = parseFloat(this.sgElement.children().css('top')) || 0
99
+ let cssObj: any = {
100
+ 'max-height': `${hotbarHeight}px`,
101
+ 'transform': 'translateY(-40%)',
102
+ };
102
103
 
103
- const middle: number = ((rectModule.height / 2) + rectModule.top)
104
- const hasPassedFromTheTop: boolean = middle - (rectSubModule.height / 2) < rectSG.top
105
- const hasPassedFromTheBottom: boolean = middle + (rectSubModule.height / 2) > rectSG.top + rectSG.height
104
+ const rectSG: DOMRect = this.sgElement[0].getBoundingClientRect();
105
+ const rectModule: DOMRect = subModule.parent()[0].getBoundingClientRect();
106
+ const rectSubModule: DOMRect = subModule[0].getBoundingClientRect();
107
+ const scrollTopPosition: number = parseFloat(this.sgElement.children().css('top')) || 0;
106
108
 
107
- if (hasPassedFromTheBottom) {
108
- const bottomScrollPosition: number =
109
- Math.abs(this.sgElement.height() - this.sgElement.children().height()) + scrollTopPosition
110
- cssObj['transform'] = 'none'
111
- cssObj['bottom'] = `${bottomScrollPosition + borderRadius}px`
112
- cssObj['top'] = ''
113
- }
114
- else if (hasPassedFromTheTop) {
115
- cssObj['transform'] = 'none'
116
- cssObj['top'] = `${scrollTopPosition * -1 + borderRadius}px`
117
- cssObj['bottom'] = ''
118
- }
119
- subModule.css(cssObj)
120
- })
109
+ const middle: number = ((rectModule.height / 2) + rectModule.top);
110
+ const hasPassedFromTheTop: boolean = middle - (rectSubModule.height / 2) < rectSG.top;
111
+ const hasPassedFromTheBottom: boolean = middle + (rectSubModule.height / 2) > rectSG.top + rectSG.height;
112
+
113
+ if (hasPassedFromTheBottom) {
114
+ const bottomScrollPosition: number = Math.abs(this.sgElement.height() - this.sgElement.children().height()) + scrollTopPosition;
115
+ cssObj.transform = 'none';
116
+ cssObj.bottom = `${bottomScrollPosition + borderRadius}px`;
117
+ cssObj.top = '';
118
+ }
119
+ else if (hasPassedFromTheTop) {
120
+ cssObj.transform = 'none';
121
+ cssObj.top = `${scrollTopPosition * -1 + borderRadius}px`;
122
+ cssObj.bottom = '';
121
123
  }
124
+ return cssObj;
122
125
  }
123
126
 
124
127
  private __onHotBarScroll(): void {
@@ -162,34 +165,10 @@ class HotbarController {
162
165
  }
163
166
 
164
167
  private __updateHotbar(): void {
165
- const quickMenuSize: number = this.config && this.config.quickMenu!.links.length
166
168
  this.modules = this.$element.find('module')
167
169
  this.subModules = this.$element.find('sub-module')
168
170
  this.__onHotBarScroll()
169
171
  this.__onResize()
170
-
171
- this.modules.each((index: number, value: Element): void => {
172
- this.__buildOnIfDoesntExists('click', value, (): void => {
173
- let $module: JQuery = $(value)
174
- $module.on('click', (evt: JQueryEventObject): void => {
175
- if ($(this.subModules[index]).find(evt.target).length == 0) {
176
- this.__onClickModule(index, $module)
177
- }
178
- })
179
- })
180
- })
181
-
182
- this.subModules.each((index: number, subModuleElement: Element): void => {
183
- const subModule: JQuery = $(subModuleElement)
184
- subModule.children().each((index2: number, optionElement: Element): void => {
185
- this.__buildOnIfDoesntExists('click', optionElement, (): void => {
186
- let option: JQuery = $(optionElement)
187
- option.on('click', (): void => {
188
- this.__onClickSubModule(index - 1 - quickMenuSize, index2)
189
- })
190
- })
191
- })
192
- })
193
172
  }
194
173
 
195
174
  private __buildOnIfDoesntExists(on: string, inElement: Element, callback: GenericFunction): void {
@@ -197,21 +176,13 @@ class HotbarController {
197
176
  if (!events || !events[on] || events[on].length == 0) callback()
198
177
  }
199
178
 
200
- private __onClickModule(index: number, element: JQuery): void {
201
- if (!index) {
202
- this.config.quickMenu!.open = !this.config.quickMenu!.open
203
- this.reloadComponent()
204
- return
205
- }
206
- if (!element.attr('main')) {
207
- if (this.openedIndexSub) $(this.modules[this.openedIndexSub]).removeClass('force-open-sub')
208
- $(element).addClass('force-open-sub')
209
- this.openedIndexSub = index
210
- } else {
211
- const quickMenuSize: number = this.config.quickMenu!.links.length
212
- this.__onClickSubModule(-1, index - 1)
213
- this.currentIndexSelection = (this.currentIndexSelection + index) % (quickMenuSize + 1)
214
- }
179
+ public onClickMain(): void {
180
+ this.config.quickMenu!.open = !this.config.quickMenu!.open
181
+ this.reloadComponent()
182
+ }
183
+
184
+ public onClickModule(index: number): void {
185
+ this.openedIndexSub = index
215
186
  try{
216
187
  this.$scope.$digest()
217
188
  }catch{}
@@ -242,28 +213,19 @@ class HotbarController {
242
213
  }, 300);
243
214
  }
244
215
 
245
- private __onClickSubModule(index: number, index2: number): void {
246
- if(this.openedIndexSub){
247
- $(this.modules[this.openedIndexSub]).removeClass('force-open-sub')
248
- this.openedIndexSub = undefined
249
- }
250
- const subModuleConfig: SubModule = index > -1 ? this.config.structure![index].children[index2] : this.config.quickMenu!.links[index2]
251
- if (index == -1) {
252
- this.__onSubModuleSelected(subModuleConfig)
253
- this.reloadComponent()
254
- } else {
255
- this.__onSubModuleSelected(subModuleConfig)
256
- }
257
- }
258
-
259
- private async __onSubModuleSelected(subModuleConfig: SubModule): Promise<void> {
216
+ public async onSubModuleSelected(subModuleConfig: SubModule, reload: boolean, event: MouseEvent): Promise<void> {
217
+ event.stopPropagation()
218
+ event.preventDefault()
219
+ this.openedIndexSub = undefined
260
220
  let access: boolean = true
221
+ document.body.focus()
261
222
  if (subModuleConfig && !!subModuleConfig.key && (this.config.keys || []).indexOf(subModuleConfig.key) === -1) {
262
223
  if (this.config.authAccess) {
263
224
  access = await this.config.authAccess(subModuleConfig)
264
225
  }
265
226
  }
266
227
  if (access) {
228
+ this.openedIndexSub = undefined
267
229
  switch (subModuleConfig.actionType) {
268
230
  case 'state':
269
231
  if (typeof subModuleConfig.action == 'string') {
@@ -294,6 +256,9 @@ class HotbarController {
294
256
  })
295
257
  })
296
258
  }
259
+ if (reload) {
260
+ this.reloadComponent()
261
+ }
297
262
  }
298
263
  }
299
264
 
@@ -304,9 +269,6 @@ const hotbar = {
304
269
  },
305
270
  template,
306
271
  controller: HotbarController,
307
- transclude: {
308
- 'module': '?module',
309
- },
310
272
  controllerAs: 'vm'
311
273
  };
312
274
 
@@ -29,6 +29,10 @@ interface Offset {
29
29
  left: number,
30
30
  }
31
31
 
32
+ export interface CssInterface {
33
+ [cssKey:string]:string
34
+ }
35
+
32
36
  interface $Scope {
33
37
  $new(isolate?: boolean, parent?: $Scope): $Scope;
34
38
  $watch(watchExpression: string | Function, listener: (newValue: any, oldValue: any, scope: $Scope) => void, objectEquality?: boolean): () => void;
@@ -1,34 +1,4 @@
1
1
  <div class="side-menu-wrapper" ng-class="{'opened-size':vm.menuOpen}">
2
2
  <hotbar config="vm.config" open="vm.menuOpen">
3
- <module main="true">
4
- <div>
5
- <i class="{{vm.config.quickMenu.icon || 'fas fa-times'}}"></i>
6
- <label>{{vm.config.quickMenu.buttonText}}</label>
7
- </div>
8
- <sub-module>
9
- </sub-module>
10
- </module>
11
- <module main="true" ng-repeat="module in vm.config.quickMenu.links" ng-hide="vm.forceHide" ng-class="{'hidden':!vm.config.quickMenu.open}">
12
- <div >
13
- <i class="{{module.icon}}"></i>
14
- <label>{{module.label}}</label>
15
- <sub-module>
16
- </sub-module>
17
- </div>
18
- </module>
19
- <module ng-repeat="module in vm.config.structure" ng-if="module.label && module.children" ng-hide="vm.forceHide" ng-class="{'hidden':vm.config.quickMenu.open}">
20
- <div>
21
- <i ng-if="module.icon && module.icon != ''"
22
- class="{{module.icon}}">
23
- </i>
24
- <label>{{module.label}}</label>
25
- </div>
26
- <sub-module>
27
- <div ng-if="!subModule.hide" ng-repeat="subModule in module.children">
28
- <i class="{{subModule.icon}}"></i>
29
- <label>{{subModule.label}}</label>
30
- </div>
31
- </sub-module>
32
- </module>
33
3
  </hotbar>
34
4
  </div>