c.c436d42d.js 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import{a as s,H as o,e as t,t as a,$ as i,Z as e,a0 as r,a1 as c,a2 as d,a3 as h,a4 as n,s as l,d as p,r as m,n as u}from"./main-ad130be7.js";import{c as v}from"./c.4a97632a.js";import"./c.f1291e50.js";import"./c.d262aab0.js";import"./c.3da15c48.js";import"./c.82e03b89.js";import"./c.9b92f489.js";import"./c.82eccc94.js";import"./c.8e28b461.js";import"./c.3f859915.js";import"./c.0ca5587f.js";import"./c.42d6aebd.js";import"./c.710a50fc.js";let g=s([u("hacs-custom-repositories-dialog")],(function(s,o){return{F:class extends o{constructor(...o){super(...o),s(this)}},d:[{kind:"field",decorators:[t()],key:"_error",value:void 0},{kind:"field",decorators:[a()],key:"_progress",value:()=>!1},{kind:"field",decorators:[a()],key:"_addRepositoryData",value:()=>({category:void 0,repository:void 0})},{kind:"field",decorators:[a()],key:"_customRepositories",value:void 0},{kind:"method",key:"shouldUpdate",value:function(s){return s.has("narrow")||s.has("active")||s.has("_error")||s.has("_addRepositoryData")||s.has("_customRepositories")||s.has("_progress")}},{kind:"method",key:"render",value:function(){var s,o;if(!this.active)return i``;const t=[{name:"repository",selector:{text:{}}},{name:"category",selector:{select:{mode:"dropdown",options:this.hacs.info.categories.map((s=>({value:s,label:this.hacs.localize(`common.${s}`)})))}}}];return i`
  2. <hacs-dialog
  3. .active=${this.active}
  4. .hass=${this.hass}
  5. .title=${this.hacs.localize("dialog_custom_repositories.title")}
  6. scrimClickAction
  7. escapeKeyAction
  8. maxWidth
  9. >
  10. <div class="content">
  11. <div class="list" ?narrow=${this.narrow}>
  12. ${null!==(s=this._error)&&void 0!==s&&s.message?i`<ha-alert alert-type="error" .rtl=${v(this.hass)}>
  13. ${this._error.message}
  14. </ha-alert>`:""}
  15. ${null===(o=this._customRepositories)||void 0===o?void 0:o.filter((s=>this.hacs.info.categories.includes(s.category))).map((s=>i`<a
  16. href="/hacs/repository/${s.id}"
  17. @click=${()=>this.active=!1}
  18. >
  19. <ha-settings-row>
  20. <span slot="heading">${s.name}</span>
  21. <span slot="description">${s.full_name} (${s.category})</span>
  22. <mwc-icon-button
  23. @click=${o=>{o.preventDefault(),this._removeRepository(String(s.id))}}
  24. >
  25. <ha-svg-icon class="delete" .path=${e}></ha-svg-icon>
  26. </mwc-icon-button>
  27. </ha-settings-row>
  28. </a>`))}
  29. </div>
  30. <ha-form
  31. ?narrow=${this.narrow}
  32. .data=${this._addRepositoryData}
  33. .schema=${t}
  34. .computeLabel=${s=>"category"===s.name?this.hacs.localize("dialog_custom_repositories.category"):this.hacs.localize("common.repository")}
  35. @value-changed=${this._valueChanged}
  36. >
  37. </ha-form>
  38. </div>
  39. <mwc-button
  40. slot="primaryaction"
  41. raised
  42. .disabled=${void 0===this._addRepositoryData.category||void 0===this._addRepositoryData.repository}
  43. @click=${this._addRepository}
  44. >
  45. ${this._progress?i`<ha-circular-progress active size="small"></ha-circular-progress>`:this.hacs.localize("common.add")}
  46. </mwc-button>
  47. </hacs-dialog>
  48. `}},{kind:"method",key:"firstUpdated",value:function(){var s;r(this.hass,(s=>this._error=s),c.ERROR),this._customRepositories=null===(s=this.hacs.repositories)||void 0===s?void 0:s.filter((s=>s.custom))}},{kind:"method",key:"_valueChanged",value:function(s){this._addRepositoryData=s.detail.value}},{kind:"method",key:"_addRepository",value:async function(){if(this._error=void 0,this._progress=!0,!this._addRepositoryData.category)return void(this._error={message:this.hacs.localize("dialog_custom_repositories.no_category")});if(!this._addRepositoryData.repository)return void(this._error={message:this.hacs.localize("dialog_custom_repositories.no_repository")});await d(this.hass,this._addRepositoryData.repository,this._addRepositoryData.category);const s=await h(this.hass);this.dispatchEvent(new CustomEvent("update-hacs",{detail:{repositories:s},bubbles:!0,composed:!0})),this._customRepositories=s.filter((s=>s.custom)),this._progress=!1}},{kind:"method",key:"_removeRepository",value:async function(s){this._error=void 0,await n(this.hass,s);const o=await h(this.hass);this.dispatchEvent(new CustomEvent("update-hacs",{detail:{repositories:o},bubbles:!0,composed:!0})),this._customRepositories=o.filter((s=>s.custom))}},{kind:"get",static:!0,key:"styles",value:function(){return[l,p,m`
  49. .list {
  50. position: relative;
  51. max-height: calc(100vh - 500px);
  52. overflow: auto;
  53. }
  54. a {
  55. all: unset;
  56. }
  57. ha-form {
  58. display: block;
  59. padding: 25px 0;
  60. }
  61. ha-form[narrow] {
  62. background-color: var(--card-background-color);
  63. bottom: 0;
  64. position: absolute;
  65. width: calc(100% - 48px);
  66. }
  67. ha-svg-icon {
  68. --mdc-icon-size: 36px;
  69. }
  70. ha-svg-icon:not(.delete) {
  71. margin-right: 4px;
  72. }
  73. ha-settings-row {
  74. cursor: pointer;
  75. padding: 0;
  76. }
  77. .list[narrow] > ha-settings-row:last-of-type {
  78. margin-bottom: 162px;
  79. }
  80. .delete {
  81. color: var(--hcv-color-error);
  82. }
  83. @media all and (max-width: 450px), all and (max-height: 500px) {
  84. .list {
  85. max-height: calc(100vh - 162px);
  86. }
  87. }
  88. `]}}]}}),o);export{g as HacsCustomRepositoriesDialog};