@gravitee/ui-components 3.25.3-typescript-50960c3 → 3.25.3-typescript-9d19b68

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,860 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvProperties=void 0;const e=require("lit");require("./gv-schema-form"),require("./gv-resizable-views"),require("../molecules/gv-table"),require("../atoms/gv-button"),require("../atoms/gv-input"),require("../atoms/gv-icon"),require("../atoms/gv-text"),require("../atoms/gv-input-message"),require("../atoms/gv-select");const t=require("../lib/events"),i=require("../lib/properties"),r=require("../lib/i18n"),o=require("lit/directives/class-map"),s=require("../mixins/keyboard-element"),n=require("../styles/empty");class a extends((0,s.KeyboardElement)(e.LitElement)){static get properties(){return{dynamicPropertySchema:{type:Object},properties:{type:Array},_properties:{type:Array,attribute:!1},provider:{type:Object},providers:{type:Array},_propertySchemaForm:{type:Object,attribute:!1},expert:{type:Boolean},_formattedErrors:{type:Array,attributes:!1},_filter:{type:String},_paginationData:{type:Object,attribute:!1},_pageSize:{type:Number,attribute:!1},_newItem:{type:Object,attribute:!1},_providerDocumentation:{type:Boolean,attribute:!1},_showDocumentation:{type:Boolean,attribute:!1},_textRows:{type:Number,attribute:!1},readonly:{type:Boolean,reflect:!0},encryptable:{type:Boolean,reflect:!0}}}constructor(){super(),this.properties=[],this.types=[],this.provider={},this._currentResource=null,this._formattedErrors=[],this._showDocumentation=!0,this._newItem={key:"",value:"",_new:!0},this._pageSize=10,this._textRows=10,this._pageSizes=[5,10,25,50,100],this._errors=[]}onKeyboard(){if(this.isPressed(s.KEYS.Esc)&&this._onClosePropertySchemaForm(),this.isPressed(s.KEYS.Shift,s.KEYS.Ctrl,s.KEYS.Space)){const e=this.shadowRoot.querySelector("#search-property");e&&e.focus()}}set properties(e){this._properties=e.sort(((e,t)=>e.key.localeCompare(t.key))).map((e=>(e.encrypted&&(e.encryptable=!0),e)))}get properties(){return this._properties}_getResizableViews(){return this.shadowRoot.querySelector("gv-resizable-views")}_maximizeTopView(){const e=this._getResizableViews();e&&e.maximizeTop(95,5)}_maximizeBottomView(){const e=this._getResizableViews();e&&e.resize(30,70)}_splitMainViews(){const e=this._getResizableViews();e&&e.split()}_isNewLineTable(e){return!0===e._new}_onInputNew(e,t){const r=t.target;this._newItem[e]=t.detail;const{errors:o}=(0,i.parseRaw)((0,i.toNameEqualsValueString)([...this.properties,this._newItem]));this._errors=o,setTimeout((()=>{const t=this.shadowRoot.querySelector("gv-button#add-property");o.length>0||this._disabledNewLine(this._newItem)?t.setAttribute("disabled",!0):t.removeAttribute("disabled"),"key"===e&&(0===o.length?(r.removeAttribute("invalid"),r.setAttribute("valid",!0)):(r.removeAttribute("valid"),r.setAttribute("invalid",!0)))}),0)}_onInput(){(0,t.dispatchCustomEvent)(this,"change",{properties:this.properties})}_onSwitchEncrypted(e){!0===e.encrypted&&(e.value="",e.encrypted=!1,e.encryptionWarning=(0,r.i18n)("gv-properties.infos.overwrite-encryption"),this.requestUpdate()),(0,t.dispatchCustomEvent)(this,"switch-encrypted",{properties:this.properties})}_addProperty(e){delete e._new,this.properties=[e,...this._properties],this._newItem={key:"",value:"",_new:!0,encryptable:!1,encrypted:!1},(0,t.dispatchCustomEvent)(this,"change",{properties:this.properties})}_removeProperty(e){this._properties=this._properties.filter((t=>t.key!==e.key)),(0,t.dispatchCustomEvent)(this,"change",{properties:this.properties})}_disabledNewLine(e){return null==e.key||null==e.value||""===e.key.trim()||""===e.value.trim()}_submitExpertMode(){this.expert&&(this.properties=this._handleExpertModeInput(this.shadowRoot.querySelector("#expert-input").value))}_onExpertModeTextInput({detail:e}){this._handleExpertModeInput(e)}_handleExpertModeInput(e){let r=this._properties;const o=this.provider&&this.provider.enabled,s=r.filter((e=>o&&e.dynamic)),n=r.filter((e=>e.encrypted)),a=`${e}\n${(0,i.toNameEqualsValueString)(s)}\n${(0,i.toNameEqualsValueString)(n)}`,{errors:p}=(0,i.parseRaw)(a);if(this._errors=p,0===p.length){const{variables:o}=(0,i.parseRaw)(e);r=[...o,...s,...n],(0,t.dispatchCustomEvent)(this,"change",{properties:r})}return r}_onSubmitPropertyForm({detail:e}){const i=e.values;(0,t.dispatchCustomEvent)(this,"save-provider",{provider:i}),this.requestUpdate()}submit(){this.expert?this._submitExpertMode():this._onSubmit()}_onSubmit(){null==[...this.shadowRoot.querySelectorAll("form .control")].find((e=>e.invalid))&&this._addProperty(this._newItem)}_onConfigureDynamicProperties(){if(null==this.dynamicPropertySchema){const e=this.providers.reduce(((e,t)=>(e[t.id]=t.key,e)),{}),t=Object.keys(e);this.dynamicPropertySchema={properties:{enabled:{type:"boolean",title:"Enabled",description:" This service is requiring an API deployment. Do not forget to deploy API to start dynamic-properties service."},schedule:{type:"string",title:"Schedule","x-schema-form":{"cron-expression":!0}},provider:{type:"string",title:"Provider type",enum:t,default:t[0],"x-schema-form":{titleMap:e}}},required:["schedule","provider"]}}const e=this.providers[0];this._propertySchemaForm={properties:{...this.dynamicPropertySchema.properties,configuration:e.schema},required:this.dynamicPropertySchema.required},this._providerDocumentation=e.documentation,this._maximizeBottomView()}_onClosePropertySchemaForm(){this._propertySchemaForm=null,this._maximizeTopView()}_onSearchProperty({detail:e}){this._filter=e,this._onClosePropertySchemaForm()}_onClearProperty(){this._filter=null,this._onClosePropertySchemaForm()}get _errors(){return this._formattedErrors}set _errors(e){this._formattedErrors=e.map((({type:e,key:t,pos:o})=>e===i.ERROR_TYPES.INVALID_NAME?{line:o.line,msg:(0,r.i18n)("gv-properties.errors.invalid-key",{key:t})}:e===i.ERROR_TYPES.DUPLICATED_NAME?{line:o.line,msg:(0,r.i18n)("gv-properties.errors.duplicated-key",{key:t})}:e===i.ERROR_TYPES.INVALID_LINE?{line:o.line,msg:(0,r.i18n)("gv-properties.errors.invalid-line")}:e===i.ERROR_TYPES.INVALID_VALUE?{line:o.line,msg:(0,r.i18n)("gv-properties.errors.invalid-value")}:{line:"?",msg:(0,r.i18n)("gv-properties.errors.unknown")}))}_renderErrors(t=!1){return this._formattedErrors.length>0?e.html`<div class="${(0,o.classMap)({"add-form-error":!0,"add-form-error_expert":this.expert})}"><div></div><div class="error-list">${this._formattedErrors.map((({line:i,msg:o})=>e.html`<gv-input-message>${t?e.html`<strong .innerHTML="${(0,r.i18n)("gv-properties.errors.line")} ${i}: "></strong>`:""} <span .innerHTML="${o}"></span></gv-input-message>`))}</div></div>`:e.html``}_renderTable(){const t=this.provider&&this.provider.enabled;if(this.expert){this._computeTextRows();const i=(t?this._properties.filter((e=>!(t&&e.dynamic))):this._properties).filter((e=>!e.encrypted)).map((e=>`${e.key}="${e.value}"`)).join("\n");return e.html`<gv-text id="expert-input" placeholder="${(0,r.i18n)("gv-properties.placeholder.input")}" @gv-text:input="${this._onExpertModeTextInput}" .value="${i}" ?readonly="${this.readonly}" .rows="${this._textRows}"></gv-text>${this._renderErrors(!0)}`}{const i={data:[{field:"dynamic",label:"Dynamic",width:"40px",type:e=>e.dynamic&&t?"gv-icon":"div",attributes:{shape:e=>e.dynamic&&t?"code:time-schedule":"",title:e=>e.dynamic&&t?"Dynamic properties service is actually in running":"",style:"justify-content: center; align-items: center; height: 100%;"}},{field:"key",label:"Key",type:"gv-input",attributes:{clipboard:!0,placeholder:(0,r.i18n)("gv-properties.placeholder.key"),name:"key",required:!0,readonly:this.readonly}},{field:"value",label:"Value",type:"gv-input",attributes:{name:"value",placeholder:"Property value",required:!0,readonly:this.readonly,disabled:e=>e.dynamic&&t||e.encrypted,type:e=>e.encrypted?"password":"text",title:e=>e.encrypted?(0,r.i18n)("gv-properties.infos.encrypted-value"):"",description:e=>e.encryptionWarning,icon:null,"ongv-input:input":this._onInput.bind(this)}}]};!0===this.encryptable&&i.data.push({field:"encryptable",type:"gv-switch",style:"--gv-switch--ta: right;",width:"105px",attributes:{description:(0,r.i18n)("gv-properties.encrypted-toggle"),required:!0,readonly:this.readonly,disabled:e=>e.dynamic&&t,"ongv-switch:input":this._onSwitchEncrypted.bind(this),style:"display: inline-flex; font-size: 12px; height: 40px;"}}),!0!==this.readonly&&i.data.push({type:"gv-button",width:"40px",attributes:{"ongv-button:click":(e,t,i)=>this._removeProperty(e,i),title:"Remove",disabled:e=>e.dynamic&&t,danger:!0,outlined:!0,icon:"home:trash"}});const o=null!=this._filter?this._properties.filter((e=>(e.key.toLowerCase()+e.value.toLowerCase()).includes(this._filter))):this._properties;let s=[...o];if(this._paginationData){this._paginationData.last=Math.ceil(o.length/this._pageSize),this._paginationData.total=o.length,this._paginationData.total_pages=Math.ceil(o.length/this._pageSize);const e=(this._paginationData.current_page-1)*this._pageSize;s=[...o].splice(e,this._pageSize)}const n=this.encryptable?"add-form-grid-with-encrypted-toggle":"add-form-grid",a=!0!==this.readonly?e.html`<form id="add-property-form" class="add-form ${n}" @submit="${this._onSubmit}"><div></div><gv-input class="control" placeholder="${(0,r.i18n)("gv-properties.placeholder.key")}" required @gv-input:input="${this._onInputNew.bind(this,"key")}" value="${this._newItem.key}"></gv-input><gv-input class="control" placeholder="${(0,r.i18n)("gv-properties.placeholder.value")}" required @gv-input:input="${this._onInputNew.bind(this,"value")}" .value="${this._newItem.value}"></gv-input>${this.encryptable?e.html`<gv-switch class="control" required description="${(0,r.i18n)("gv-properties.encrypted-toggle")}" @gv-switch:input="${this._onInputNew.bind(this,"encryptable")}" .value="${this._newItem.encryptable}"></gv-switch>`:""}<gv-button id="add-property" icon="code:plus" outlined disabled="disabled" @gv-button:click="${this._addProperty.bind(this,this._newItem)}" title="${(0,r.i18n)("gv-properties.add")}"></gv-button></form>${this._renderErrors()}<hr>`:"";return e.html`${a}<gv-table .options="${i}" .items="${s}" noheader nosort order="key" rowheight="57px"></gv-table>`}}_onChangeMode({detail:e}){this._submitExpertMode(),this.expert=e,this._errors=[],this._newItem={key:"",value:"",_new:!0},this._onClosePropertySchemaForm()}_onPaginate({detail:e}){this._paginationData.current_page=e.page,this._onClosePropertySchemaForm(),this.requestUpdate()}updated(e){(e.has("_properties")||e.has("_pageSize"))&&(this._paginationData={first:1,last:Math.ceil(this._properties.length/this._pageSize),total:this._properties.length,current_page:1,total_pages:Math.ceil(this._properties.length/this._pageSize)})}_onChangePageSize({detail:e}){this._pageSize=Number(e).valueOf(),this._onClosePropertySchemaForm()}_renderTableForm(){return e.html`<div class="container"><div class="header"><div class="title">Manage global properties <span>(${this._properties?this._properties.length:0})</span></div><gv-switch small .description="${this.expert?"Expert":"Simple"}" .value="${this.expert}" @gv-switch:input="${this._onChangeMode}"></gv-switch><gv-input id="search-property" placeholder="Filter properties (Shift + Ctrl + Space)" type="search" small class="search-input" .disabled="${this.expert}" @gv-input:input="${this._onSearchProperty}" @gv-input:clear="${this._onClearProperty}"></gv-input><gv-select class="page-size__select" @gv-select:input="${this._onChangePageSize}" small .options="${this._pageSizes}" .value="${this._pageSize}" .disabled="${this.expert||null==this._paginationData}"></gv-select><gv-pagination @gv-pagination:paginate="${this._onPaginate}" .disabled="${this.expert||null==this._paginationData}" .data="${this._paginationData}" widget></gv-pagination></div><div class="content"><div class="form-content">${this._renderTable()}</div></div></div>`}_fetchDocumentation(){this._showDocumentation=!0}_hideDocumentation(){this._showDocumentation=!1}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._onClosePropertySchemaForm())):Promise.resolve()}_renderForm(){return e.html`<gv-schema-form slot="top" scrollable .schema="${this._propertySchemaForm}" .values="${this.provider}" .icon="design:edit" has-header ?readonly="${this.readonly}" @gv-schema-form:submit="${this._onSubmitPropertyForm}"><div slot="title" class="properties-title">Configure dynamic properties</div><gv-button slot="header-left" icon="general:close" outlined small @gv-button:click="${this._onClosePropertySchemaForm}" title="Close (esc)"></gv-button><gv-button slot="header-left" icon="home:book" ?disabled="${this._showDocumentation}" outlined small @gv-button:click="${this._fetchDocumentation}" title="Open documentation"></gv-button></gv-schema-form>`}_renderBottom(){return this._propertySchemaForm&&this._showDocumentation?e.html`<gv-resizable-views no-overflow direction="horizontal">${this._renderForm()}<gv-documentation slot="bottom" .text="${this._providerDocumentation}" @gv-documentation:close="${this._hideDocumentation}"></gv-documentation></gv-resizable-views>`:this._propertySchemaForm?this._renderForm():e.html`<div class="properties-bottom-container">${this._renderDynamicConfiguration()}</div>`}_renderDynamicConfiguration(){const t=this.provider&&this.provider.enabled;let i="";return(t||!0!==this.readonly)&&(i=e.html`<gv-button icon="tools:tools" @gv-button:click="${this._onConfigureDynamicProperties}" outlined .disabled="${this.expert}">Configure dynamic properties</gv-button>`),t?e.html`<div class="properties-message">Dynamic properties service is actually in <code>running</code> state and run with cron expression <code>${this.provider.schedule}</code> using <code>${this.provider.provider}</code> provider.</div>${i}`:this.readonly?e.html`<div class="empty">No dynamic properties service configured</div>`:i}_onMove(){this._computeTextRows()}_computeTextRows(){const e=this.shadowRoot.querySelector(".content");if(e){const{height:t}=e.getBoundingClientRect();this._textRows=Math.round(Math.round(t-20)/30)-2}}render(){return this.providers&&this.providers.length>0?e.html`<div class="properties"><gv-resizable-views no-overflow @gv-resizable-views:move="${this._onMove}" @gv-resizable-views:resize="${this._onMove}"><div slot="top" class="box">${this._renderTableForm()}</div><div slot="bottom">${this._renderBottom()}</div></gv-resizable-views></div>`:e.html`<div class="properties"><div class="table-box">${this._renderTableForm()}</div></div>`}static get styles(){return[n.empty,e.css`:host{box-sizing:border-box;height:100%;width:100%;display:block}.properties{display:flex;height:100%;width:100%}gv-resizable-views{height:100%;width:100%}gv-schema-form{margin:0}.table-box{width:100%;border-left:1px solid #bfbfbf;display:flex}gv-table{height:auto;flex:1;margin-top:10px;margin-right:50px;--gv-table-rows--ov:none;--gv-table--colmg:var(--gv-properties-table--colmg, 0.2rem);--gv-table-cell--d:inline;--gv-table-row--ai:flex-start;--gv-table-row--ac:flex-start;--gv-table-hover--bgc:var(--gv-theme-neutral-color-lightest)}.properties-title{text-transform:uppercase;letter-spacing:.2rem}.properties-bottom-container{display:flex;justify-content:center;align-items:center;height:100%;flex-direction:column}.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}gv-text{--gv-text--fz:20px;--gv-text--lh:25px}gv-switch{--gv-switch--ta:right}.header gv-input{margin:0 1rem}.add-form,.add-form-error{display:grid;margin:auto 50px auto 0;box-sizing:border-box}.add-form{column-gap:var(--gv-properties-table--colmg,.2rem);border-right:solid thick transparent;height:50px}.add-form gv-input,gv-button,gv-switch{margin:auto 0}.add-form gv-switch{font-size:12px}.add-form-grid{grid-template-columns:40px auto auto 40px}.add-form-grid-with-encrypted-toggle{grid-template-columns:40px auto auto 105px 40px}.add-form-error_expert{display:flex}.add-form-error{grid-template-columns:40px 1fr}code{color:var(--gv-theme-color-warning-dark,#f57c00)}.form-content{display:flex;flex-direction:column;width:100%}.properties-message{margin-bottom:.5rem;font-size:14px}.page-size__select{max-width:50px}.search-input{width:300px}hr{background-color:var(--gv-theme-neutral-color);border:0;width:100%;height:2px}`]}}exports.GvProperties=a,window.customElements.define("gv-properties",a);
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 '../molecules/gv-table';
20
+ import '../atoms/gv-button';
21
+ import '../atoms/gv-input';
22
+ import '../atoms/gv-icon';
23
+ import '../atoms/gv-text';
24
+ import '../atoms/gv-input-message';
25
+ import '../atoms/gv-select';
26
+ import { dispatchCustomEvent } from '../lib/events';
27
+ import { ERROR_TYPES, parseRaw, toNameEqualsValueString } from '../lib/properties';
28
+ import { i18n } from '../lib/i18n';
29
+ import { classMap } from 'lit/directives/class-map';
30
+ import { KeyboardElement, KEYS } from '../mixins/keyboard-element';
31
+ import { empty } from '../styles/empty';
32
+ /**
33
+ * A component to manage properties
34
+ *
35
+ * @fires gv-properties:change - When list of properties change
36
+ * @fires gv-properties:save-provider - When user validates provider configuration
37
+ * @fires gv-properties:switch-encrypted - When user switches encryption toggle
38
+ *
39
+ * @attr {Array} properties - Array of Properties {key, value, dynamic?}
40
+ * @attr {Object} provider - Configuration of provider
41
+ * @attr {Array} providers - List of available providers (only http for the moment)
42
+ * @attr {Boolean} expert - For display expert mode by default
43
+ * @attr {Boolean} encryptable - To display the 'encrypted' toggle on each property
44
+ *
45
+ * @cssprop {Length} [--gv-properties-table--colmg=0.2rem] - Table cells margin
46
+ */
47
+ export class GvProperties extends KeyboardElement(LitElement) {
48
+ static get properties() {
49
+ return {
50
+ dynamicPropertySchema: { type: Object },
51
+ properties: { type: Array },
52
+ _properties: { type: Array, attribute: false },
53
+ provider: { type: Object },
54
+ providers: { type: Array },
55
+ _propertySchemaForm: { type: Object, attribute: false },
56
+ expert: { type: Boolean },
57
+ _formattedErrors: { type: Array, attributes: false },
58
+ _filter: { type: String },
59
+ _paginationData: { type: Object, attribute: false },
60
+ _pageSize: { type: Number, attribute: false },
61
+ _newItem: { type: Object, attribute: false },
62
+ _providerDocumentation: { type: Boolean, attribute: false },
63
+ _showDocumentation: { type: Boolean, attribute: false },
64
+ _textRows: { type: Number, attribute: false },
65
+ readonly: { type: Boolean, reflect: true },
66
+ encryptable: { type: Boolean, reflect: true },
67
+ };
68
+ }
69
+ constructor() {
70
+ super();
71
+ this.properties = [];
72
+ this.types = [];
73
+ this.provider = {};
74
+ this._currentResource = null;
75
+ this._formattedErrors = [];
76
+ this._showDocumentation = true;
77
+ this._newItem = { key: '', value: '', _new: true };
78
+ this._pageSize = 10;
79
+ this._textRows = 10;
80
+ this._pageSizes = [5, 10, 25, 50, 100];
81
+ this._errors = [];
82
+ }
83
+ onKeyboard() {
84
+ if (this.isPressed(KEYS.Esc)) {
85
+ this._onClosePropertySchemaForm();
86
+ }
87
+ if (this.isPressed(KEYS.Shift, KEYS.Ctrl, KEYS.Space)) {
88
+ const search = this.shadowRoot.querySelector('#search-property');
89
+ if (search) {
90
+ search.focus();
91
+ }
92
+ }
93
+ }
94
+ set properties(properties) {
95
+ this._properties = properties
96
+ .sort((a, b) => a.key.localeCompare(b.key))
97
+ .map((property) => {
98
+ if (property.encrypted) {
99
+ property.encryptable = true;
100
+ }
101
+ return property;
102
+ });
103
+ }
104
+ get properties() {
105
+ return this._properties;
106
+ }
107
+ _getResizableViews() {
108
+ return this.shadowRoot.querySelector('gv-resizable-views');
109
+ }
110
+ _maximizeTopView() {
111
+ const views = this._getResizableViews();
112
+ if (views) {
113
+ views.maximizeTop(95, 5);
114
+ }
115
+ }
116
+ _maximizeBottomView() {
117
+ const views = this._getResizableViews();
118
+ if (views) {
119
+ views.resize(30, 70);
120
+ }
121
+ }
122
+ _splitMainViews() {
123
+ const views = this._getResizableViews();
124
+ if (views) {
125
+ views.split();
126
+ }
127
+ }
128
+ _isNewLineTable(line) {
129
+ return line._new === true;
130
+ }
131
+ _onInputNew(name, event) {
132
+ const target = event.target;
133
+ this._newItem[name] = event.detail;
134
+ const { errors } = parseRaw(toNameEqualsValueString([...this.properties, this._newItem]));
135
+ this._errors = errors;
136
+ setTimeout(() => {
137
+ const btn = this.shadowRoot.querySelector('gv-button#add-property');
138
+ if (errors.length > 0 || this._disabledNewLine(this._newItem)) {
139
+ btn.setAttribute('disabled', true);
140
+ }
141
+ else {
142
+ btn.removeAttribute('disabled');
143
+ }
144
+ if (name === 'key') {
145
+ if (errors.length === 0) {
146
+ target.removeAttribute('invalid');
147
+ target.setAttribute('valid', true);
148
+ }
149
+ else {
150
+ target.removeAttribute('valid');
151
+ target.setAttribute('invalid', true);
152
+ }
153
+ }
154
+ }, 0);
155
+ }
156
+ _onInput() {
157
+ dispatchCustomEvent(this, 'change', { properties: this.properties });
158
+ }
159
+ _onSwitchEncrypted(item) {
160
+ if (item.encrypted === true) {
161
+ item.value = '';
162
+ item.encrypted = false;
163
+ item.encryptionWarning = i18n('gv-properties.infos.overwrite-encryption');
164
+ this.requestUpdate();
165
+ }
166
+ dispatchCustomEvent(this, 'switch-encrypted', { properties: this.properties });
167
+ }
168
+ _addProperty(item) {
169
+ delete item._new;
170
+ this.properties = [item, ...this._properties];
171
+ this._newItem = { key: '', value: '', _new: true, encryptable: false, encrypted: false };
172
+ dispatchCustomEvent(this, 'change', { properties: this.properties });
173
+ }
174
+ _removeProperty(item) {
175
+ this._properties = this._properties.filter((property) => property.key !== item.key);
176
+ dispatchCustomEvent(this, 'change', { properties: this.properties });
177
+ }
178
+ _disabledNewLine(item) {
179
+ return item.key == null || item.value == null || item.key.trim() === '' || item.value.trim() === '';
180
+ }
181
+ _submitExpertMode() {
182
+ if (this.expert) {
183
+ this.properties = this._handleExpertModeInput(this.shadowRoot.querySelector('#expert-input').value);
184
+ }
185
+ }
186
+ _onExpertModeTextInput({ detail }) {
187
+ this._handleExpertModeInput(detail);
188
+ }
189
+ _handleExpertModeInput(expertModeInputString) {
190
+ let allProperties = this._properties;
191
+ const providerEnabled = this.provider && this.provider.enabled;
192
+ const dynamicProperties = allProperties.filter((prop) => providerEnabled && prop.dynamic);
193
+ const encryptedProperties = allProperties.filter((prop) => prop.encrypted);
194
+ const allPropertiesString = `${expertModeInputString}\n${toNameEqualsValueString(dynamicProperties)}\n${toNameEqualsValueString(encryptedProperties)}`;
195
+ const { errors } = parseRaw(allPropertiesString);
196
+ this._errors = errors;
197
+ if (errors.length === 0) {
198
+ const { variables } = parseRaw(expertModeInputString);
199
+ allProperties = [...variables, ...dynamicProperties, ...encryptedProperties];
200
+ dispatchCustomEvent(this, 'change', { properties: allProperties });
201
+ }
202
+ return allProperties;
203
+ }
204
+ _onSubmitPropertyForm({ detail }) {
205
+ const provider = detail.values;
206
+ dispatchCustomEvent(this, 'save-provider', { provider });
207
+ this.requestUpdate();
208
+ }
209
+ submit() {
210
+ if (this.expert) {
211
+ this._submitExpertMode();
212
+ }
213
+ else {
214
+ this._onSubmit();
215
+ }
216
+ }
217
+ _onSubmit() {
218
+ const invalidControls = [...this.shadowRoot.querySelectorAll('form .control')].find((control) => control.invalid);
219
+ if (invalidControls == null) {
220
+ this._addProperty(this._newItem);
221
+ }
222
+ }
223
+ _onConfigureDynamicProperties() {
224
+ if (this.dynamicPropertySchema == null) {
225
+ // dynamicPropertySchema has been introduced to ensure backward compatibility with old versions. If no schema is provided a default schema will be used.
226
+ const providersTitleMap = this.providers.reduce((map, provider) => {
227
+ map[provider.id] = provider.key;
228
+ return map;
229
+ }, {});
230
+ const providersEnum = Object.keys(providersTitleMap);
231
+ this.dynamicPropertySchema = {
232
+ properties: {
233
+ enabled: {
234
+ type: 'boolean',
235
+ title: 'Enabled',
236
+ description: ' This service is requiring an API deployment. Do not forget to deploy API to start dynamic-properties service.',
237
+ },
238
+ schedule: {
239
+ type: 'string',
240
+ title: 'Schedule',
241
+ 'x-schema-form': {
242
+ 'cron-expression': true,
243
+ },
244
+ },
245
+ provider: {
246
+ type: 'string',
247
+ title: 'Provider type',
248
+ enum: providersEnum,
249
+ default: providersEnum[0],
250
+ 'x-schema-form': {
251
+ titleMap: providersTitleMap,
252
+ },
253
+ },
254
+ },
255
+ required: ['schedule', 'provider'],
256
+ };
257
+ }
258
+ const defaultProvider = this.providers[0];
259
+ this._propertySchemaForm = {
260
+ properties: { ...this.dynamicPropertySchema.properties, configuration: defaultProvider.schema },
261
+ required: this.dynamicPropertySchema.required,
262
+ };
263
+ this._providerDocumentation = defaultProvider.documentation;
264
+ this._maximizeBottomView();
265
+ }
266
+ _onClosePropertySchemaForm() {
267
+ this._propertySchemaForm = null;
268
+ this._maximizeTopView();
269
+ }
270
+ _onSearchProperty({ detail }) {
271
+ this._filter = detail;
272
+ this._onClosePropertySchemaForm();
273
+ }
274
+ _onClearProperty() {
275
+ this._filter = null;
276
+ this._onClosePropertySchemaForm();
277
+ }
278
+ get _errors() {
279
+ return this._formattedErrors;
280
+ }
281
+ set _errors(rawErrors) {
282
+ this._formattedErrors = rawErrors.map(({ type, key, pos }) => {
283
+ if (type === ERROR_TYPES.INVALID_NAME) {
284
+ return {
285
+ line: pos.line,
286
+ msg: i18n('gv-properties.errors.invalid-key', { key }),
287
+ };
288
+ }
289
+ if (type === ERROR_TYPES.DUPLICATED_NAME) {
290
+ return {
291
+ line: pos.line,
292
+ msg: i18n('gv-properties.errors.duplicated-key', { key }),
293
+ };
294
+ }
295
+ if (type === ERROR_TYPES.INVALID_LINE) {
296
+ return {
297
+ line: pos.line,
298
+ msg: i18n('gv-properties.errors.invalid-line'),
299
+ };
300
+ }
301
+ if (type === ERROR_TYPES.INVALID_VALUE) {
302
+ return {
303
+ line: pos.line,
304
+ msg: i18n('gv-properties.errors.invalid-value'),
305
+ };
306
+ }
307
+ return { line: '?', msg: i18n('gv-properties.errors.unknown') };
308
+ });
309
+ }
310
+ _renderErrors(withLine = false) {
311
+ if (this._formattedErrors.length > 0) {
312
+ return html `<div class="${classMap({ 'add-form-error': true, 'add-form-error_expert': this.expert })}">
313
+ <div></div>
314
+ <div class="error-list">
315
+ ${this._formattedErrors.map(({ line, msg }) => html `
316
+ <gv-input-message
317
+ >${withLine ? html `<strong .innerHTML="${i18n('gv-properties.errors.line')} ${line}:&nbsp;"></strong>` : ''}
318
+ <span .innerHTML="${msg}"></span
319
+ ></gv-input-message>
320
+ `)}
321
+ </div>
322
+ </div>`;
323
+ }
324
+ return html ``;
325
+ }
326
+ _renderTable() {
327
+ const providerEnabled = this.provider && this.provider.enabled;
328
+ if (this.expert) {
329
+ this._computeTextRows();
330
+ const staticProperties = providerEnabled ? this._properties.filter((prop) => !(providerEnabled && prop.dynamic)) : this._properties;
331
+ const expertProperties = staticProperties.filter((prop) => !prop.encrypted);
332
+ const content = expertProperties.map((prop) => `${prop.key}="${prop.value}"`).join('\n');
333
+ return html `<gv-text
334
+ id="expert-input"
335
+ placeholder="${i18n('gv-properties.placeholder.input')}"
336
+ @gv-text:input="${this._onExpertModeTextInput}"
337
+ .value="${content}"
338
+ ?readonly="${this.readonly}"
339
+ .rows="${this._textRows}"
340
+ ></gv-text>
341
+ ${this._renderErrors(true)}`;
342
+ }
343
+ else {
344
+ const options = {
345
+ data: [
346
+ {
347
+ field: 'dynamic',
348
+ label: 'Dynamic',
349
+ width: '40px',
350
+ type: (item) => (item.dynamic && providerEnabled ? 'gv-icon' : 'div'),
351
+ attributes: {
352
+ shape: (item) => (item.dynamic && providerEnabled ? 'code:time-schedule' : ''),
353
+ title: (item) => (item.dynamic && providerEnabled ? 'Dynamic properties service is actually in running' : ''),
354
+ style: 'justify-content: center; align-items: center; height: 100%;',
355
+ },
356
+ },
357
+ {
358
+ field: 'key',
359
+ label: 'Key',
360
+ type: 'gv-input',
361
+ attributes: {
362
+ clipboard: true,
363
+ placeholder: i18n('gv-properties.placeholder.key'),
364
+ name: 'key',
365
+ required: true,
366
+ readonly: this.readonly,
367
+ },
368
+ },
369
+ {
370
+ field: 'value',
371
+ label: 'Value',
372
+ type: 'gv-input',
373
+ attributes: {
374
+ name: 'value',
375
+ placeholder: 'Property value',
376
+ required: true,
377
+ readonly: this.readonly,
378
+ disabled: (item) => (item.dynamic && providerEnabled) || item.encrypted,
379
+ type: (item) => (item.encrypted ? 'password' : 'text'),
380
+ title: (item) => (item.encrypted ? i18n('gv-properties.infos.encrypted-value') : ''),
381
+ description: (item) => item.encryptionWarning,
382
+ icon: null,
383
+ 'ongv-input:input': this._onInput.bind(this),
384
+ },
385
+ },
386
+ ],
387
+ };
388
+ if (this.encryptable === true) {
389
+ options.data.push({
390
+ field: 'encryptable',
391
+ type: 'gv-switch',
392
+ style: '--gv-switch--ta: right;',
393
+ width: '105px',
394
+ attributes: {
395
+ description: i18n('gv-properties.encrypted-toggle'),
396
+ required: true,
397
+ readonly: this.readonly,
398
+ disabled: (item) => item.dynamic && providerEnabled,
399
+ 'ongv-switch:input': this._onSwitchEncrypted.bind(this),
400
+ style: 'display: inline-flex; font-size: 12px; height: 40px;',
401
+ },
402
+ });
403
+ }
404
+ if (this.readonly !== true) {
405
+ options.data.push({
406
+ type: 'gv-button',
407
+ width: '40px',
408
+ attributes: {
409
+ 'ongv-button:click': (item, event, target) => this._removeProperty(item, target),
410
+ title: 'Remove',
411
+ disabled: (item) => item.dynamic && providerEnabled,
412
+ danger: true,
413
+ outlined: true,
414
+ icon: 'home:trash',
415
+ },
416
+ });
417
+ }
418
+ const filteredProperties = this._filter != null
419
+ ? this._properties.filter((prop) => {
420
+ return (prop.key.toLowerCase() + prop.value.toLowerCase()).includes(this._filter);
421
+ })
422
+ : this._properties;
423
+ let properties = [...filteredProperties];
424
+ if (this._paginationData) {
425
+ this._paginationData.last = Math.ceil(filteredProperties.length / this._pageSize);
426
+ this._paginationData.total = filteredProperties.length;
427
+ this._paginationData.total_pages = Math.ceil(filteredProperties.length / this._pageSize);
428
+ const index = (this._paginationData.current_page - 1) * this._pageSize;
429
+ properties = [...filteredProperties].splice(index, this._pageSize);
430
+ }
431
+ const addPropertyFormGridClass = this.encryptable ? 'add-form-grid-with-encrypted-toggle' : 'add-form-grid';
432
+ const addPropertyForm = this.readonly !== true
433
+ ? html `<form id="add-property-form" class="add-form ${addPropertyFormGridClass}" @submit="${this._onSubmit}">
434
+ <div></div>
435
+ <gv-input
436
+ class="control"
437
+ placeholder="${i18n('gv-properties.placeholder.key')}"
438
+ required
439
+ @gv-input:input="${this._onInputNew.bind(this, 'key')}"
440
+ value="${this._newItem.key}"
441
+ ></gv-input>
442
+ <gv-input
443
+ class="control"
444
+ placeholder="${i18n('gv-properties.placeholder.value')}"
445
+ required
446
+ @gv-input:input="${this._onInputNew.bind(this, 'value')}"
447
+ .value="${this._newItem.value}"
448
+ ></gv-input>
449
+ ${this.encryptable
450
+ ? html ` <gv-switch
451
+ class="control"
452
+ required
453
+ description="${i18n('gv-properties.encrypted-toggle')}"
454
+ @gv-switch:input="${this._onInputNew.bind(this, 'encryptable')}"
455
+ .value="${this._newItem.encryptable}"
456
+ ></gv-switch>`
457
+ : ''}
458
+ <gv-button
459
+ id="add-property"
460
+ icon="code:plus"
461
+ outlined
462
+ disabled
463
+ @gv-button:click="${this._addProperty.bind(this, this._newItem)}"
464
+ title="${i18n('gv-properties.add')}"
465
+ ></gv-button>
466
+ </form>
467
+ ${this._renderErrors()}
468
+ <hr />`
469
+ : '';
470
+ return html ` ${addPropertyForm}
471
+ <gv-table .options="${options}" .items="${properties}" noheader nosort order="key" rowheight="57px"></gv-table>`;
472
+ }
473
+ }
474
+ _onChangeMode({ detail }) {
475
+ this._submitExpertMode();
476
+ this.expert = detail;
477
+ this._errors = [];
478
+ this._newItem = { key: '', value: '', _new: true };
479
+ this._onClosePropertySchemaForm();
480
+ }
481
+ _onPaginate({ detail }) {
482
+ this._paginationData.current_page = detail.page;
483
+ this._onClosePropertySchemaForm();
484
+ this.requestUpdate();
485
+ }
486
+ updated(props) {
487
+ if (props.has('_properties') || props.has('_pageSize')) {
488
+ this._paginationData = {
489
+ first: 1,
490
+ last: Math.ceil(this._properties.length / this._pageSize),
491
+ total: this._properties.length,
492
+ current_page: 1,
493
+ total_pages: Math.ceil(this._properties.length / this._pageSize),
494
+ };
495
+ }
496
+ }
497
+ _onChangePageSize({ detail }) {
498
+ this._pageSize = Number(detail).valueOf();
499
+ this._onClosePropertySchemaForm();
500
+ }
501
+ _renderTableForm() {
502
+ return html `<div class="container">
503
+ <div class="header">
504
+ <div class="title">Manage global properties <span>(${this._properties ? this._properties.length : 0})</span></div>
505
+ <gv-switch
506
+ small
507
+ .description="${this.expert ? 'Expert' : 'Simple'}"
508
+ .value="${this.expert}"
509
+ @gv-switch:input="${this._onChangeMode}"
510
+ ></gv-switch>
511
+ <gv-input
512
+ id="search-property"
513
+ placeholder="Filter properties (Shift + Ctrl + Space)"
514
+ type="search"
515
+ small
516
+ class="search-input"
517
+ .disabled="${this.expert}"
518
+ @gv-input:input="${this._onSearchProperty}"
519
+ @gv-input:clear="${this._onClearProperty}"
520
+ ></gv-input>
521
+ <gv-select
522
+ class="page-size__select"
523
+ @gv-select:input="${this._onChangePageSize}"
524
+ small
525
+ .options="${this._pageSizes}"
526
+ .value="${this._pageSize}"
527
+ .disabled="${this.expert || this._paginationData == null}"
528
+ ></gv-select>
529
+ <gv-pagination
530
+ @gv-pagination:paginate="${this._onPaginate}"
531
+ .disabled="${this.expert || this._paginationData == null}"
532
+ .data="${this._paginationData}"
533
+ widget
534
+ ></gv-pagination>
535
+ </div>
536
+ <div class="content"><div class="form-content">${this._renderTable()}</div></div>
537
+ </div>`;
538
+ }
539
+ _fetchDocumentation() {
540
+ this._showDocumentation = true;
541
+ }
542
+ _hideDocumentation() {
543
+ this._showDocumentation = false;
544
+ }
545
+ get dirty() {
546
+ const form = this.shadowRoot.querySelector('gv-schema-form');
547
+ return form && form.dirty;
548
+ }
549
+ confirm() {
550
+ const form = this.shadowRoot.querySelector('gv-schema-form');
551
+ if (form) {
552
+ return form.confirm().then(() => this._onClosePropertySchemaForm());
553
+ }
554
+ return Promise.resolve();
555
+ }
556
+ _renderForm() {
557
+ return html `<gv-schema-form
558
+ slot="top"
559
+ scrollable
560
+ .schema="${this._propertySchemaForm}"
561
+ .values="${this.provider}"
562
+ .icon="design:edit"
563
+ has-header
564
+ ?readonly="${this.readonly}"
565
+ @gv-schema-form:submit="${this._onSubmitPropertyForm}"
566
+ >
567
+ <div slot="title" class="properties-title">Configure dynamic properties</div>
568
+ <gv-button
569
+ slot="header-left"
570
+ icon="general:close"
571
+ outlined
572
+ small
573
+ @gv-button:click="${this._onClosePropertySchemaForm}"
574
+ title="Close (esc)"
575
+ ></gv-button>
576
+ <gv-button
577
+ slot="header-left"
578
+ icon="home:book"
579
+ ?disabled="${this._showDocumentation}"
580
+ outlined
581
+ small
582
+ @gv-button:click="${this._fetchDocumentation}"
583
+ title="Open documentation"
584
+ ></gv-button>
585
+ </gv-schema-form>`;
586
+ }
587
+ _renderBottom() {
588
+ if (this._propertySchemaForm && this._showDocumentation) {
589
+ return html `<gv-resizable-views no-overflow direction="horizontal">
590
+ ${this._renderForm()}
591
+ <gv-documentation
592
+ slot="bottom"
593
+ .text="${this._providerDocumentation}"
594
+ @gv-documentation:close="${this._hideDocumentation}"
595
+ ></gv-documentation>
596
+ </gv-resizable-views>`;
597
+ }
598
+ else if (this._propertySchemaForm) {
599
+ return this._renderForm();
600
+ }
601
+ else {
602
+ return html `<div class="properties-bottom-container">${this._renderDynamicConfiguration()}</div>`;
603
+ }
604
+ }
605
+ _renderDynamicConfiguration() {
606
+ const hasDynamicConfiguration = this.provider && this.provider.enabled;
607
+ let configureAction = '';
608
+ if (hasDynamicConfiguration || this.readonly !== true) {
609
+ configureAction = html `<gv-button
610
+ icon="tools:tools"
611
+ @gv-button:click="${this._onConfigureDynamicProperties}"
612
+ outlined
613
+ .disabled="${this.expert}"
614
+ >Configure dynamic properties</gv-button
615
+ >`;
616
+ }
617
+ if (hasDynamicConfiguration) {
618
+ return html `<div class="properties-message">
619
+ Dynamic properties service is actually in <code>running</code> state and run with cron expression
620
+ <code>${this.provider.schedule}</code> using <code>${this.provider.provider}</code> provider.
621
+ </div>
622
+ ${configureAction}`;
623
+ }
624
+ else if (this.readonly) {
625
+ return html `<div class="empty">No dynamic properties service configured</div>`;
626
+ }
627
+ else {
628
+ return configureAction;
629
+ }
630
+ }
631
+ _onMove() {
632
+ this._computeTextRows();
633
+ }
634
+ _computeTextRows() {
635
+ const parent = this.shadowRoot.querySelector('.content');
636
+ if (parent) {
637
+ const { height } = parent.getBoundingClientRect();
638
+ // --gv-text--lh=30px
639
+ this._textRows = Math.round(Math.round(height - 20) / 30) - 2;
640
+ }
641
+ }
642
+ render() {
643
+ if (this.providers && this.providers.length > 0) {
644
+ return html `<div class="properties">
645
+ <gv-resizable-views no-overflow @gv-resizable-views:move="${this._onMove}" @gv-resizable-views:resize="${this._onMove}">
646
+ <div slot="top" class="box">${this._renderTableForm()}</div>
647
+ <div slot="bottom">${this._renderBottom()}</div>
648
+ </gv-resizable-views>
649
+ </div>`;
650
+ }
651
+ else {
652
+ return html `<div class="properties">
653
+ <div class="table-box">${this._renderTableForm()}</div>
654
+ </div>`;
655
+ }
656
+ }
657
+ static get styles() {
658
+ return [
659
+ empty,
660
+ // language=CSS
661
+ css `
662
+ :host {
663
+ box-sizing: border-box;
664
+ height: 100%;
665
+ width: 100%;
666
+ display: block;
667
+ }
668
+
669
+ .properties {
670
+ display: flex;
671
+ height: 100%;
672
+ width: 100%;
673
+ }
674
+
675
+ gv-resizable-views {
676
+ height: 100%;
677
+ width: 100%;
678
+ }
679
+
680
+ gv-schema-form {
681
+ margin: 0;
682
+ }
683
+
684
+ .table-box {
685
+ width: 100%;
686
+ border-left: 1px solid #bfbfbf;
687
+ display: flex;
688
+ }
689
+
690
+ gv-table {
691
+ height: auto;
692
+ flex: 1;
693
+ margin-top: 10px;
694
+ margin-right: 50px;
695
+ --gv-table-rows--ov: none;
696
+ --gv-table--colmg: var(--gv-properties-table--colmg, 0.2rem);
697
+ --gv-table-cell--d: inline;
698
+ --gv-table-row--ai: flex-start;
699
+ --gv-table-row--ac: flex-start;
700
+ --gv-table-hover--bgc: var(--gv-theme-neutral-color-lightest);
701
+ }
702
+
703
+ .properties-title {
704
+ text-transform: uppercase;
705
+ letter-spacing: 0.2rem;
706
+ }
707
+
708
+ .properties-bottom-container {
709
+ display: flex;
710
+ justify-content: center;
711
+ align-items: center;
712
+ height: 100%;
713
+ flex-direction: column;
714
+ }
715
+
716
+ .header {
717
+ border-bottom: 1px solid #d9d9d9;
718
+ display: flex;
719
+ min-height: 45px;
720
+ align-items: center;
721
+ margin-bottom: 0.5rem;
722
+ padding: 0 0.5rem;
723
+ }
724
+
725
+ .header .title {
726
+ color: #28444f;
727
+ font-size: 18px;
728
+ display: flex;
729
+ align-items: flex-end;
730
+ flex: 1;
731
+ }
732
+
733
+ .header .title span {
734
+ font-size: 12px;
735
+ margin-left: 8px;
736
+ opacity: 0.7;
737
+ }
738
+
739
+ .box {
740
+ position: absolute;
741
+ display: flex;
742
+ flex-direction: column;
743
+ width: 100%;
744
+ top: 0;
745
+ bottom: 0;
746
+ left: 0;
747
+ }
748
+
749
+ .container {
750
+ flex-grow: 1;
751
+
752
+ display: flex;
753
+ flex-direction: column;
754
+
755
+ /* for Firefox */
756
+ min-height: 0;
757
+ height: 100%;
758
+ }
759
+
760
+ .content {
761
+ background: white;
762
+ flex-grow: 1;
763
+
764
+ overflow: auto;
765
+
766
+ /* for Firefox */
767
+ min-height: 0;
768
+ padding: 0.5rem;
769
+
770
+ display: flex;
771
+ flex-direction: column;
772
+ align-items: center;
773
+ }
774
+
775
+ gv-text {
776
+ --gv-text--fz: 20px;
777
+ --gv-text--lh: 25px;
778
+ }
779
+
780
+ gv-switch {
781
+ --gv-switch--ta: right;
782
+ }
783
+
784
+ .header gv-input {
785
+ margin: 0 1rem;
786
+ }
787
+
788
+ .add-form,
789
+ .add-form-error {
790
+ display: grid;
791
+ margin: auto 50px auto 0;
792
+ box-sizing: border-box;
793
+ }
794
+
795
+ .add-form {
796
+ column-gap: var(--gv-properties-table--colmg, 0.2rem);
797
+ border-right: solid thick transparent;
798
+ height: 50px;
799
+ }
800
+
801
+ .add-form gv-input,
802
+ gv-button,
803
+ gv-switch {
804
+ margin: auto 0;
805
+ }
806
+
807
+ .add-form gv-switch {
808
+ font-size: 12px;
809
+ }
810
+
811
+ .add-form-grid {
812
+ grid-template-columns: 40px auto auto 40px;
813
+ }
814
+
815
+ .add-form-grid-with-encrypted-toggle {
816
+ grid-template-columns: 40px auto auto 105px 40px;
817
+ }
818
+
819
+ .add-form-error_expert {
820
+ display: flex;
821
+ }
822
+
823
+ .add-form-error {
824
+ grid-template-columns: 40px 1fr;
825
+ }
826
+
827
+ code {
828
+ color: var(--gv-theme-color-warning-dark, #f57c00);
829
+ }
830
+
831
+ .form-content {
832
+ display: flex;
833
+ flex-direction: column;
834
+ width: 100%;
835
+ }
836
+
837
+ .properties-message {
838
+ margin-bottom: 0.5rem;
839
+ font-size: 14px;
840
+ }
841
+
842
+ .page-size__select {
843
+ max-width: 50px;
844
+ }
845
+
846
+ .search-input {
847
+ width: 300px;
848
+ }
849
+
850
+ hr {
851
+ background-color: var(--gv-theme-neutral-color);
852
+ border: 0;
853
+ width: 100%;
854
+ height: 2px;
855
+ }
856
+ `,
857
+ ];
858
+ }
859
+ }
860
+ window.customElements.define('gv-properties', GvProperties);