@gravitee/ui-components 3.25.3-typescript-fdacf14 → 3.25.3-typescript-493e1dd

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.
Files changed (183) hide show
  1. package/package.json +5 -13
  2. package/src/atoms/gv-autocomplete.js +422 -1
  3. package/src/atoms/gv-button.js +397 -1
  4. package/src/atoms/gv-checkbox.js +178 -1
  5. package/src/atoms/gv-date-picker-calendar.js +812 -1
  6. package/src/atoms/gv-date-picker-cell.js +174 -1
  7. package/src/atoms/gv-date-picker.js +638 -1
  8. package/src/atoms/gv-file-upload.js +348 -1
  9. package/src/atoms/gv-icon.js +93 -1
  10. package/src/atoms/gv-image.js +135 -1
  11. package/src/atoms/gv-input-message.js +78 -1
  12. package/src/atoms/gv-input.js +508 -1
  13. package/src/atoms/gv-link.js +204 -1
  14. package/src/atoms/gv-message.js +133 -1
  15. package/src/atoms/gv-metric.js +112 -1
  16. package/src/atoms/gv-relative-time.js +143 -1
  17. package/src/atoms/gv-select-native.js +363 -1
  18. package/src/atoms/gv-select.js +413 -1
  19. package/src/atoms/gv-spinner.js +54 -1
  20. package/src/atoms/gv-state.js +125 -1
  21. package/src/atoms/gv-switch.js +235 -1
  22. package/src/atoms/gv-tag.js +162 -1
  23. package/src/atoms/gv-text.js +160 -1
  24. package/src/charts/gv-chart-bar.js +101 -1
  25. package/src/charts/gv-chart-gauge.js +92 -1
  26. package/src/charts/gv-chart-histogram.js +78 -1
  27. package/src/charts/gv-chart-line.js +218 -1
  28. package/src/charts/gv-chart-map.js +111 -1
  29. package/src/charts/gv-chart-pie.js +89 -1
  30. package/src/index.js +77 -1
  31. package/src/lib/cron-expression.js +176 -1
  32. package/src/lib/date.js +43 -1
  33. package/src/lib/events.js +26 -1
  34. package/src/lib/http-client-schema-form.js +67 -1
  35. package/src/lib/http.js +237 -1
  36. package/src/lib/i18n.js +93 -1
  37. package/src/lib/item.js +110 -1
  38. package/src/lib/properties.js +171 -1
  39. package/src/lib/schema-form.js +39 -1
  40. package/src/lib/studio.js +144 -1
  41. package/src/lib/style.js +39 -1
  42. package/src/lib/text-format.js +65 -1
  43. package/src/lib/theme.js +60 -1
  44. package/src/lib/utils.js +106 -1
  45. package/src/mixins/chart-element.js +153 -1
  46. package/src/mixins/input-element.js +136 -1
  47. package/src/mixins/item-resource.js +102 -1
  48. package/src/mixins/keyboard-element.js +62 -1
  49. package/src/mixins/update-after-browser.js +30 -1
  50. package/src/mixins/with-resize-observer.js +62 -1
  51. package/src/mixins/with-skeleton-attribute.js +109 -1
  52. package/src/molecules/gv-card-full.js +209 -1
  53. package/src/molecules/gv-card-list.js +101 -1
  54. package/src/molecules/gv-card.js +130 -1
  55. package/src/molecules/gv-category-list.js +56 -1
  56. package/src/molecules/gv-category.js +163 -1
  57. package/src/molecules/gv-code.js +334 -1
  58. package/src/molecules/gv-confirm.js +175 -1
  59. package/src/molecules/gv-cron-editor.js +685 -1
  60. package/src/molecules/gv-dropdown-menu.js +108 -1
  61. package/src/molecules/gv-expandable.js +116 -1
  62. package/src/molecules/gv-expression-language.js +263 -1
  63. package/src/molecules/gv-identity-picture.js +139 -1
  64. package/src/molecules/gv-list.js +214 -1
  65. package/src/molecules/gv-metrics.js +147 -1
  66. package/src/molecules/gv-modal.js +203 -1
  67. package/src/molecules/gv-nav.js +180 -1
  68. package/src/molecules/gv-option.js +230 -1
  69. package/src/molecules/gv-plans.js +400 -1
  70. package/src/molecules/gv-popover.js +323 -1
  71. package/src/molecules/gv-promote.js +203 -1
  72. package/src/molecules/gv-rating-list.js +341 -1
  73. package/src/molecules/gv-rating.js +234 -1
  74. package/src/molecules/gv-row-expandable.js +42 -1
  75. package/src/molecules/gv-row.js +205 -1
  76. package/src/molecules/gv-stats.js +110 -1
  77. package/src/molecules/gv-stepper.js +274 -1
  78. package/src/molecules/gv-table.js +644 -1
  79. package/src/molecules/gv-tree.js +238 -1
  80. package/src/organisms/gv-documentation.js +205 -1
  81. package/src/organisms/gv-header.js +276 -1
  82. package/src/organisms/gv-http-client.js +258 -1
  83. package/src/organisms/gv-menu.js +258 -1
  84. package/src/organisms/gv-newsletter-subscription.js +258 -1
  85. package/src/organisms/gv-pagination.js +179 -1
  86. package/src/organisms/gv-properties.js +860 -1
  87. package/src/organisms/gv-resizable-views.js +371 -1
  88. package/src/organisms/gv-resources.js +496 -1
  89. package/src/organisms/gv-schema-form-array.js +237 -1
  90. package/src/organisms/gv-schema-form-control-object.js +141 -1
  91. package/src/organisms/gv-schema-form-control.js +419 -1
  92. package/src/organisms/gv-schema-form.js +700 -1
  93. package/src/organisms/gv-tabs.js +201 -1
  94. package/src/organisms/gv-user-menu.js +298 -1
  95. package/src/organisms/gv-vertical-menu.js +119 -1
  96. package/src/policy-studio/gv-flow-step.js +443 -1
  97. package/src/policy-studio/gv-flow.js +595 -1
  98. package/src/policy-studio/gv-policy-studio-menu.js +689 -1
  99. package/src/policy-studio/gv-policy-studio.js +1712 -1
  100. package/src/styles/empty.js +35 -1
  101. package/src/styles/input.js +262 -1
  102. package/src/styles/link.js +31 -1
  103. package/src/styles/shapes.js +17 -1
  104. package/src/styles/skeleton.js +52 -1
  105. package/src/styles/zoom.js +39 -1
  106. package/src/theme/gv-theme.js +197 -1
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
@@ -1 +1,496 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvResources=void 0;const e=require("lit");require("./gv-schema-form"),require("./gv-resizable-views"),require("./gv-documentation"),require("../molecules/gv-table"),require("../atoms/gv-button"),require("../molecules/gv-option"),require("../atoms/gv-switch"),require("../atoms/gv-icon");const t=require("../lib/events"),s=require("../lib/utils"),i=require("../mixins/keyboard-element"),r=require("../styles/empty");class o extends((0,i.KeyboardElement)(e.LitElement)){static get properties(){return{resources:{type:Array},_resources:{type:Array,attribute:!1},types:{type:Array},documentation:{type:Object},_currentResource:{type:Object,attribute:!1},_currentResourceLoading:{type:Boolean,attribute:!1},_filter:{type:String},readonly:{type:Boolean,reflect:!0}}}constructor(){super(),this.resources=[],this.types=[],this._currentResource=null,this._emptymessage="No resource"}onKeyboard(){if(this.isPressed(i.KEYS.Esc)&&this._onCancelResourceForm(),this.isPressed(i.KEYS.Shift,i.KEYS.Ctrl,i.KEYS.Space)){const e=this.shadowRoot.querySelector("#search-resource");e&&e.focus()}}firstUpdated(){const e=this.shadowRoot.querySelector("gv-resizable-views");null!=e&&e.updateComplete.then((()=>{this._maximizeTopView()}))}set resources(e){this._resources=this._generateId(e)}get resources(){return this._resources}_generateId(e){return e?e.map((e=>(null==e._id&&(e._id=(0,s.uuid)()),e))):e}_getResizableViews(){return this.shadowRoot.querySelector("gv-resizable-views")}_maximizeTopView(){this._getResizableViews().resize(60,40)}_maximizeBottomView(){this._getResizableViews().maximizeBottom()}_splitMainViews(){this._getResizableViews().split()}_onCancelResourceForm(){this._currentResource=null,this.documentation=null,this._maximizeTopView()}_removeResource(e){this.resources=this.resources.filter((t=>t._id!==e._id)),this._onCancelResourceForm(),(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_buildResourceSchema(e){const t={properties:{name:{type:"string",title:"Resource name"}},required:["name"]},s="string"==typeof e.schema?JSON.parse(e.schema):e.schema;return{properties:{...t.properties,...s.properties},required:[...t.required,...s.required]}}_onCreateResource({detail:e}){this._currentResourceLoading=!0;const t=this.types.find((t=>t.id===e.id)),s=this._buildResourceSchema(t);this._currentResource={type:t.id,title:"Create resource",icon:"code:plus",schema:s,values:{},submitLabel:"Add",dirty:!0},this._maximizeBottomView(),this._onFetchDocumentation(),setTimeout((()=>this._currentResourceLoading=!1),600)}_onSubmitResourceForm({detail:e}){delete this._currentResource._values;const{type:i}=this._currentResource,{_id:r,name:o,...n}=e.values,c={_id:r,type:i,name:o,configuration:n};if(null!=e.values._id){const e=this.resources.findIndex((e=>e._id===c._id));this.resources[e]={...this.resources[e],...c}}else null==this.resources&&(this.resources=[]),c._id=(0,s.uuid)(),c.enabled=!0,this.resources.push(c);this._onCancelResourceForm(),(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_onChangeResourceForm({detail:e}){this._currentResource._values=e.values}_onResetResourceForm(){delete this._currentResource._values}_findResourceById(e){return this.types.find((t=>t.id===e))}_onSelectResource({detail:{items:e}}){e.length>0?this._onEditResource(e[0]):this._onCancelResourceForm()}_onEditResource(e){const t={...e,...e.configuration};delete t.configuration;const s=this._findResourceById(e.type);this._currentResource={_id:e._id,title:"Resource configuration",type:e.type,icon:"design:edit",schema:this._buildResourceSchema(s),values:t,submitLabel:"Update"},this._splitMainViews(),this._onFetchDocumentation()}_onCloseDocumentation(){this.documentation=null}_getCurrentResourceType(){return this._currentResource?this._findResourceById(this._currentResource.type):null}_onFetchDocumentation(){(0,t.dispatchCustomEvent)(this,"fetch-documentation",{target:this,resourceType:this._getCurrentResourceType()})}get dirty(){const e=this.shadowRoot.querySelector("gv-schema-form");return e&&e.dirty}confirm(){const e=this.shadowRoot.querySelector("gv-schema-form");return e?e.confirm().then((()=>this._onCancelResourceForm())):Promise.resolve()}_onChangeResourceState(e,s){const i=this.resources.find((t=>t._id===e._id));this.resources[i]={...this.resources[i],enabled:e.enabled},(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_renderForm(){const t={...this._currentResource.values,...this._currentResource._values};return e.html`<gv-schema-form scrollable .schema="${this._currentResource.schema}" .values="${t}" submitLabel="${this._currentResource.submitLabel}" has-header .icon="${this._currentResource.icon}" validate-on-render .dirty="${this._currentResource.dirty||null!=this._currentResource._values}" ?readonly="${this.readonly}" @gv-schema-form:change="${this._onChangeResourceForm}" @gv-schema-form:reset="${this._onResetResourceForm}" @gv-schema-form:submit="${this._onSubmitResourceForm}"><div slot="title" class="form-title">${this._currentResource.title}</div><gv-button slot="header-left" icon="general:close" outlined small @gv-button:click="${this._onCancelResourceForm}" title="Close (esc)"></gv-button><gv-button slot="header-left" icon="home:book" ?disabled="${null!=this.documentation}" outlined small @gv-button:click="${this._onFetchDocumentation}" title="Open documentation"></gv-button></gv-schema-form>`}_renderDoc(){return e.html`<gv-documentation .text="${this.documentation.content}" .image="${this.documentation.image}" @gv-documentation:close="${this._onCloseDocumentation}"></gv-documentation>`}_renderBottom(){if(this.documentation&&this._currentResource)return e.html`<gv-resizable-views direction="horizontal" no-overflow><div slot="top">${this._renderForm()}</div><div slot="bottom">${this._renderDoc()}</div></gv-resizable-views>`;if(this._currentResource)return this._renderForm();if(this.documentation)return this._renderDoc();if(!0!==this.readonly){const t=this.types.map((e=>({id:e.id,title:e.name,description:e.description,image:e.icon})));return e.html`<div class="resources-bottom-container"><gv-option class="resource__option" .options="${t}" @gv-option:select="${this._onCreateResource}"></gv-option></div>`}return this.readonly&&this.resources.length>0?e.html`<div class="resources-bottom-container empty">You can see the resource configuration by clicking on it</div>`:void 0}_onSearchResource({detail:e}){this._filter=e}_onClearResource(){this._filter=null}render(){const t={selectable:!0,data:[{field:"name",label:"Name"},{field:"type",width:"50px",type:"gv-image",attributes:{src:e=>{const t=this._findResourceById(e.type);return t?t.icon:null},style:"width:40px;height:40px;"}},{field:"type",label:"Type"},{field:"enabled",type:"gv-switch",title:e=>e.enabled?"Click to disable":"Click to enable",width:"50px",attributes:{readonly:this.readonly,"ongv-switch:input":(e,t)=>this._onChangeResourceState(e,t)}}]};!0!==this.readonly&&t.data.push({type:"gv-button",width:"50px",attributes:{onClick:e=>this._removeResource(e),title:"remove",danger:!0,outlined:!0,icon:"home:trash"}});const s=null!=this._filter?this.resources.filter((e=>(e.name.toLowerCase()+e.type.toLowerCase()).includes(this._filter))):this.resources;return e.html`<div class="resources"><gv-resizable-views no-overflow><div slot="top" class="box"><div class="container"><div class="header"><div class="title">Manage global resources <span>(${this.resources.length})</span></div><gv-input id="search-resource" class="search-input" placeholder="Filter resources (Shift + Ctrl + Space)" type="search" small @gv-input:input="${this._onSearchResource}" @gv-input:clear="${this._onClearResource}"></gv-input></div><div class="content"><div class="table-container"><gv-table .options="${t}" .items="${s}" emptymessage="${this._emptymessage}" @gv-table:select="${this._onSelectResource}" order="name" rowheight="50px"></gv-table></div></div></div></div><div slot="bottom">${this._renderBottom()}</div></gv-resizable-views></div>`}static get styles(){return[r.empty,e.css`:host{box-sizing:border-box;height:100%;width:100%;display:block}.resources{display:flex;height:100%;width:100%}gv-resizable-views{height:100%;width:100%}gv-table{--gv-table-rows--ov:none}.header{border-bottom:1px solid #d9d9d9;display:flex;min-height:45px;align-items:center;margin-bottom:.5rem;padding:0 .5rem}.header .title{color:#28444f;font-size:18px;display:flex;align-items:flex-end;flex:1}.header .title span{font-size:12px;margin-left:8px;opacity:.7}.box{position:absolute;display:flex;flex-direction:column;width:100%;top:0;bottom:0;left:0}.container{flex-grow:1;display:flex;flex-direction:column;min-height:0;height:100%}.content{background:#fff;flex-grow:1;overflow:auto;min-height:0;padding:.5rem;display:flex;flex-direction:column;align-items:center}.form-title{text-transform:uppercase;letter-spacing:.2rem}.resources-bottom-container{display:flex;justify-content:center;align-items:center;height:100%}.table-container{max-width:1200px;display:flex;flex-direction:column;width:100%}.search-input{width:300px}.resource__option{--gv-option-button--maw:175px}`]}}exports.GvResources=o,window.customElements.define("gv-resources",o);
1
+ /*
2
+ * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { css, html, LitElement } from 'lit';
17
+ import './gv-schema-form';
18
+ import './gv-resizable-views';
19
+ import './gv-documentation';
20
+ import '../molecules/gv-table';
21
+ import '../atoms/gv-button';
22
+ import '../molecules/gv-option';
23
+ import '../atoms/gv-switch';
24
+ import '../atoms/gv-icon';
25
+ import { dispatchCustomEvent } from '../lib/events';
26
+ import { uuid } from '../lib/utils';
27
+ import { KeyboardElement, KEYS } from '../mixins/keyboard-element';
28
+ import { empty } from '../styles/empty';
29
+ export class GvResources extends KeyboardElement(LitElement) {
30
+ static get properties() {
31
+ return {
32
+ resources: { type: Array },
33
+ _resources: { type: Array, attribute: false },
34
+ types: { type: Array },
35
+ documentation: { type: Object },
36
+ _currentResource: { type: Object, attribute: false },
37
+ _currentResourceLoading: { type: Boolean, attribute: false },
38
+ _filter: { type: String },
39
+ readonly: { type: Boolean, reflect: true },
40
+ };
41
+ }
42
+ constructor() {
43
+ super();
44
+ this.resources = [];
45
+ this.types = [];
46
+ this._currentResource = null;
47
+ this._emptymessage = 'No resource';
48
+ }
49
+ onKeyboard() {
50
+ if (this.isPressed(KEYS.Esc)) {
51
+ this._onCancelResourceForm();
52
+ }
53
+ if (this.isPressed(KEYS.Shift, KEYS.Ctrl, KEYS.Space)) {
54
+ const search = this.shadowRoot.querySelector('#search-resource');
55
+ if (search) {
56
+ search.focus();
57
+ }
58
+ }
59
+ }
60
+ firstUpdated() {
61
+ const views = this.shadowRoot.querySelector('gv-resizable-views');
62
+ if (views != null) {
63
+ views.updateComplete.then(() => {
64
+ this._maximizeTopView();
65
+ });
66
+ }
67
+ }
68
+ set resources(resources) {
69
+ this._resources = this._generateId(resources);
70
+ }
71
+ get resources() {
72
+ return this._resources;
73
+ }
74
+ _generateId(list) {
75
+ if (list) {
76
+ return list.map((e) => {
77
+ if (e._id == null) {
78
+ e._id = uuid();
79
+ }
80
+ return e;
81
+ });
82
+ }
83
+ return list;
84
+ }
85
+ _getResizableViews() {
86
+ return this.shadowRoot.querySelector('gv-resizable-views');
87
+ }
88
+ _maximizeTopView() {
89
+ this._getResizableViews().resize(60, 40);
90
+ }
91
+ _maximizeBottomView() {
92
+ this._getResizableViews().maximizeBottom();
93
+ }
94
+ _splitMainViews() {
95
+ this._getResizableViews().split();
96
+ }
97
+ _onCancelResourceForm() {
98
+ this._currentResource = null;
99
+ this.documentation = null;
100
+ this._maximizeTopView();
101
+ }
102
+ _removeResource(item) {
103
+ this.resources = this.resources.filter((resource) => resource._id !== item._id);
104
+ this._onCancelResourceForm();
105
+ dispatchCustomEvent(this, 'change', { resources: this.resources });
106
+ }
107
+ _buildResourceSchema(resourceType) {
108
+ const defaultSchema = {
109
+ properties: {
110
+ name: {
111
+ type: 'string',
112
+ title: 'Resource name',
113
+ },
114
+ },
115
+ required: ['name'],
116
+ };
117
+ const schema = typeof resourceType.schema === 'string' ? JSON.parse(resourceType.schema) : resourceType.schema;
118
+ return {
119
+ properties: { ...defaultSchema.properties, ...schema.properties },
120
+ required: [...defaultSchema.required, ...schema.required],
121
+ };
122
+ }
123
+ _onCreateResource({ detail }) {
124
+ this._currentResourceLoading = true;
125
+ const defaultResourceType = this.types.find((type) => type.id === detail.id);
126
+ const schema = this._buildResourceSchema(defaultResourceType);
127
+ this._currentResource = {
128
+ type: defaultResourceType.id,
129
+ title: 'Create resource',
130
+ icon: 'code:plus',
131
+ schema,
132
+ values: {},
133
+ submitLabel: 'Add',
134
+ dirty: true,
135
+ };
136
+ this._maximizeBottomView();
137
+ this._onFetchDocumentation();
138
+ setTimeout(() => (this._currentResourceLoading = false), 600);
139
+ }
140
+ _onSubmitResourceForm({ detail }) {
141
+ delete this._currentResource._values;
142
+ const { type } = this._currentResource;
143
+ const { _id, name, ...configuration } = detail.values;
144
+ const resource = {
145
+ _id,
146
+ type,
147
+ name,
148
+ configuration,
149
+ };
150
+ if (detail.values._id != null) {
151
+ const index = this.resources.findIndex((r) => r._id === resource._id);
152
+ this.resources[index] = { ...this.resources[index], ...resource };
153
+ }
154
+ else {
155
+ if (this.resources == null) {
156
+ this.resources = [];
157
+ }
158
+ resource._id = uuid();
159
+ resource.enabled = true;
160
+ this.resources.push(resource);
161
+ }
162
+ this._onCancelResourceForm();
163
+ dispatchCustomEvent(this, 'change', { resources: this.resources });
164
+ }
165
+ _onChangeResourceForm({ detail }) {
166
+ this._currentResource._values = detail.values;
167
+ }
168
+ _onResetResourceForm() {
169
+ delete this._currentResource._values;
170
+ }
171
+ _findResourceById(id) {
172
+ return this.types.find((resource) => resource.id === id);
173
+ }
174
+ // For readonly mode
175
+ _onSelectResource({ detail: { items } }) {
176
+ if (items.length > 0) {
177
+ this._onEditResource(items[0]);
178
+ }
179
+ else {
180
+ this._onCancelResourceForm();
181
+ }
182
+ }
183
+ _onEditResource(resource) {
184
+ const values = { ...resource, ...resource.configuration };
185
+ delete values.configuration;
186
+ const resourceType = this._findResourceById(resource.type);
187
+ this._currentResource = {
188
+ _id: resource._id,
189
+ title: 'Resource configuration',
190
+ type: resource.type,
191
+ icon: 'design:edit',
192
+ schema: this._buildResourceSchema(resourceType),
193
+ values,
194
+ submitLabel: 'Update',
195
+ };
196
+ this._splitMainViews();
197
+ this._onFetchDocumentation();
198
+ }
199
+ _onCloseDocumentation() {
200
+ this.documentation = null;
201
+ }
202
+ _getCurrentResourceType() {
203
+ return this._currentResource ? this._findResourceById(this._currentResource.type) : null;
204
+ }
205
+ _onFetchDocumentation() {
206
+ dispatchCustomEvent(this, 'fetch-documentation', { target: this, resourceType: this._getCurrentResourceType() });
207
+ }
208
+ get dirty() {
209
+ const form = this.shadowRoot.querySelector('gv-schema-form');
210
+ return form && form.dirty;
211
+ }
212
+ confirm() {
213
+ const form = this.shadowRoot.querySelector('gv-schema-form');
214
+ if (form) {
215
+ return form.confirm().then(() => this._onCancelResourceForm());
216
+ }
217
+ return Promise.resolve();
218
+ }
219
+ _onChangeResourceState(item, event) {
220
+ const index = this.resources.find((r) => r._id === item._id);
221
+ this.resources[index] = { ...this.resources[index], enabled: item.enabled };
222
+ dispatchCustomEvent(this, 'change', { resources: this.resources });
223
+ }
224
+ _renderForm() {
225
+ const values = { ...this._currentResource.values, ...this._currentResource._values };
226
+ return html `<gv-schema-form
227
+ scrollable
228
+ .schema="${this._currentResource.schema}"
229
+ .values="${values}"
230
+ submitLabel="${this._currentResource.submitLabel}"
231
+ has-header
232
+ .icon="${this._currentResource.icon}"
233
+ validate-on-render
234
+ .dirty="${this._currentResource.dirty || this._currentResource._values != null}"
235
+ ?readonly="${this.readonly}"
236
+ @gv-schema-form:change="${this._onChangeResourceForm}"
237
+ @gv-schema-form:reset="${this._onResetResourceForm}"
238
+ @gv-schema-form:submit="${this._onSubmitResourceForm}"
239
+ >
240
+ <div slot="title" class="form-title">${this._currentResource.title}</div>
241
+ <gv-button
242
+ slot="header-left"
243
+ icon="general:close"
244
+ outlined
245
+ small
246
+ @gv-button:click="${this._onCancelResourceForm}"
247
+ title="Close (esc)"
248
+ ></gv-button>
249
+ <gv-button
250
+ slot="header-left"
251
+ icon="home:book"
252
+ ?disabled="${this.documentation != null}"
253
+ outlined
254
+ small
255
+ @gv-button:click="${this._onFetchDocumentation}"
256
+ title="Open documentation"
257
+ ></gv-button>
258
+ </gv-schema-form>`;
259
+ }
260
+ _renderDoc() {
261
+ return html `<gv-documentation
262
+ .text="${this.documentation.content}"
263
+ .image="${this.documentation.image}"
264
+ @gv-documentation:close="${this._onCloseDocumentation}"
265
+ ></gv-documentation>`;
266
+ }
267
+ _renderBottom() {
268
+ if (this.documentation && this._currentResource) {
269
+ return html ` <gv-resizable-views direction="horizontal" no-overflow>
270
+ <div slot="top">${this._renderForm()}</div>
271
+ <div slot="bottom">${this._renderDoc()}</div>
272
+ </gv-resizable-views>`;
273
+ }
274
+ else if (this._currentResource) {
275
+ return this._renderForm();
276
+ }
277
+ else if (this.documentation) {
278
+ return this._renderDoc();
279
+ }
280
+ else if (this.readonly !== true) {
281
+ const resourceOpts = this.types.map((resource) => {
282
+ return { id: resource.id, title: resource.name, description: resource.description, image: resource.icon };
283
+ });
284
+ return html `<div class="resources-bottom-container">
285
+ <gv-option class="resource__option" .options="${resourceOpts}" @gv-option:select="${this._onCreateResource}">
286
+ </div>`;
287
+ }
288
+ else if (this.readonly && this.resources.length > 0) {
289
+ return html `<div class="resources-bottom-container empty">You can see the resource configuration by clicking on it</div>`;
290
+ }
291
+ }
292
+ _onSearchResource({ detail }) {
293
+ this._filter = detail;
294
+ }
295
+ _onClearResource() {
296
+ this._filter = null;
297
+ }
298
+ render() {
299
+ const options = {
300
+ selectable: true,
301
+ data: [
302
+ { field: 'name', label: 'Name' },
303
+ {
304
+ field: 'type',
305
+ width: '50px',
306
+ type: 'gv-image',
307
+ attributes: {
308
+ src: (item) => {
309
+ const resourceType = this._findResourceById(item.type);
310
+ return resourceType ? resourceType.icon : null;
311
+ },
312
+ style: 'width:40px;height:40px;',
313
+ },
314
+ },
315
+ { field: 'type', label: 'Type' },
316
+ {
317
+ field: 'enabled',
318
+ type: 'gv-switch',
319
+ title: (item) => (item.enabled ? 'Click to disable' : 'Click to enable'),
320
+ width: '50px',
321
+ attributes: {
322
+ readonly: this.readonly,
323
+ 'ongv-switch:input': (item, event) => this._onChangeResourceState(item, event),
324
+ },
325
+ },
326
+ ],
327
+ };
328
+ if (this.readonly !== true) {
329
+ options.data.push({
330
+ type: 'gv-button',
331
+ width: '50px',
332
+ attributes: {
333
+ onClick: (item) => this._removeResource(item),
334
+ title: 'remove',
335
+ danger: true,
336
+ outlined: true,
337
+ icon: 'home:trash',
338
+ },
339
+ });
340
+ }
341
+ const filteredResources = this._filter != null
342
+ ? this.resources.filter((resource) => {
343
+ return (resource.name.toLowerCase() + resource.type.toLowerCase()).includes(this._filter);
344
+ })
345
+ : this.resources;
346
+ return html `<div class="resources">
347
+ <gv-resizable-views no-overflow>
348
+ <div slot="top" class="box">
349
+ <div class="container">
350
+ <div class="header">
351
+ <div class="title">Manage global resources <span>(${this.resources.length})</span></div>
352
+ <gv-input
353
+ id="search-resource"
354
+ class="search-input"
355
+ placeholder="Filter resources (Shift + Ctrl + Space)"
356
+ type="search"
357
+ small
358
+ @gv-input:input="${this._onSearchResource}"
359
+ @gv-input:clear="${this._onClearResource}"
360
+ ></gv-input>
361
+ </div>
362
+ <div class="content">
363
+ <div class="table-container">
364
+ <gv-table
365
+ .options="${options}"
366
+ .items="${filteredResources}"
367
+ emptymessage="${this._emptymessage}"
368
+ @gv-table:select="${this._onSelectResource}"
369
+ order="name"
370
+ rowheight="50px"
371
+ ></gv-table>
372
+ </div>
373
+ </div>
374
+ </div>
375
+ </div>
376
+ <div slot="bottom">${this._renderBottom()}</div>
377
+ </gv-resizable-views>
378
+ </div>`;
379
+ }
380
+ static get styles() {
381
+ return [
382
+ empty,
383
+ // language=CSS
384
+ css `
385
+ :host {
386
+ box-sizing: border-box;
387
+ height: 100%;
388
+ width: 100%;
389
+ display: block;
390
+ }
391
+
392
+ .resources {
393
+ display: flex;
394
+ height: 100%;
395
+ width: 100%;
396
+ }
397
+
398
+ gv-resizable-views {
399
+ height: 100%;
400
+ width: 100%;
401
+ }
402
+
403
+ gv-table {
404
+ --gv-table-rows--ov: none;
405
+ }
406
+
407
+ .header {
408
+ border-bottom: 1px solid #d9d9d9;
409
+ display: flex;
410
+ min-height: 45px;
411
+ align-items: center;
412
+ margin-bottom: 0.5rem;
413
+ padding: 0 0.5rem;
414
+ }
415
+
416
+ .header .title {
417
+ color: #28444f;
418
+ font-size: 18px;
419
+ display: flex;
420
+ align-items: flex-end;
421
+ flex: 1;
422
+ }
423
+
424
+ .header .title span {
425
+ font-size: 12px;
426
+ margin-left: 8px;
427
+ opacity: 0.7;
428
+ }
429
+
430
+ .box {
431
+ position: absolute;
432
+ display: flex;
433
+ flex-direction: column;
434
+ width: 100%;
435
+ top: 0;
436
+ bottom: 0;
437
+ left: 0;
438
+ }
439
+
440
+ .container {
441
+ flex-grow: 1;
442
+
443
+ display: flex;
444
+ flex-direction: column;
445
+
446
+ /* for Firefox */
447
+ min-height: 0;
448
+ height: 100%;
449
+ }
450
+
451
+ .content {
452
+ background: white;
453
+ flex-grow: 1;
454
+
455
+ overflow: auto;
456
+
457
+ /* for Firefox */
458
+ min-height: 0;
459
+ padding: 0.5rem;
460
+
461
+ display: flex;
462
+ flex-direction: column;
463
+ align-items: center;
464
+ }
465
+
466
+ .form-title {
467
+ text-transform: uppercase;
468
+ letter-spacing: 0.2rem;
469
+ }
470
+
471
+ .resources-bottom-container {
472
+ display: flex;
473
+ justify-content: center;
474
+ align-items: center;
475
+ height: 100%;
476
+ }
477
+
478
+ .table-container {
479
+ max-width: 1200px;
480
+ display: flex;
481
+ flex-direction: column;
482
+ width: 100%;
483
+ }
484
+
485
+ .search-input {
486
+ width: 300px;
487
+ }
488
+
489
+ .resource__option {
490
+ --gv-option-button--maw: 175px;
491
+ }
492
+ `,
493
+ ];
494
+ }
495
+ }
496
+ window.customElements.define('gv-resources', GvResources);