UNPKG

@nextcloud/vue

Version:
56 lines (55 loc) 3.08 kB
import i from "./NcSelect.mjs"; import { t as s } from "../chunks/l10n-9a5a6afc.mjs"; import { l } from "../chunks/l10n-05baf7da.mjs"; import { G as o } from "../chunks/GenRandomId-1e1b509a.mjs"; import u from "@nextcloud/axios"; import { showError as n } from "@nextcloud/dialogs"; import { generateOcsUrl as p } from "@nextcloud/router"; import { debounce as d } from "debounce"; import { n as c } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs"; const m = { name: "NcSettingsSelectGroup", components: { NcSelect: i }, mixins: [l], props: { label: { type: String, required: !0 }, placeholder: { type: String, default: "" }, id: { type: String, default: () => "action-" + o(), validator: (e) => e.trim() !== "" }, value: { type: Array, default: () => [] }, disabled: { type: Boolean, default: !1 } }, emits: ["input", "error"], data() { return { groups: {}, randId: o() }; }, computed: { filteredValue() { return this.value.filter((e) => e !== "" && typeof e == "string"); }, inputValue() { return this.filteredValue.map((e) => typeof this.groups[e] > "u" ? { id: e, displayname: e } : this.groups[e]); }, groupsArray() { return Object.values(this.groups).filter((e) => !this.value.includes(e.id)); } }, watch: { value: { handler() { const e = Object.keys(this.groups); this.filteredValue.filter((t) => !e.includes(t)).forEach((t) => { this.loadGroup(t); }); }, immediate: !0 } }, async mounted() { const e = `${appName}:${appVersion}/initialGroups`; let t = window.sessionStorage.getItem(e); t ? (t = Object.fromEntries(JSON.parse(t).map((r) => [r.id, r])), this.groups = { ...this.groups, ...t }) : (await this.loadGroup(""), window.sessionStorage.setItem(e, JSON.stringify(Object.values(this.groups)))); }, methods: { update(e) { const t = e.map((r) => r.id); this.$emit("input", t); }, async loadGroup(e) { try { e = typeof e == "string" ? encodeURI(e) : ""; const t = await u.get(p(`cloud/groups/details?search=${e}&limit=10`, 2)); if (Object.keys(t.data.ocs.data.groups).length > 0) { const r = Object.fromEntries(t.data.ocs.data.groups.map((a) => [a.id, a])); return this.groups = { ...this.groups, ...r }, !0; } } catch (t) { this.$emit("error", t), n(s("Unable to search the group")); } return !1; }, filterGroups(e, t, r) { return `${t || ""} ${e.id}`.toLocaleLowerCase().indexOf(r.toLocaleLowerCase()) > -1; }, onSearch: d(function(e) { this.loadGroup(e); }, 200) } }; var f = function() { var e = this, t = e._self._c; return t("div", [e.label ? t("label", { staticClass: "hidden-visually", attrs: { for: e.id } }, [e._v(e._s(e.label))]) : e._e(), t("NcSelect", { attrs: { value: e.inputValue, options: e.groupsArray, placeholder: e.placeholder || e.label, "filter-by": e.filterGroups, "input-id": e.id, limit: 5, label: "displayname", multiple: !0, "close-on-select": !1, disabled: e.disabled }, on: { input: e.update, search: e.onSearch } })], 1); }, h = [], g = c(m, f, h, !1, null, null, null, null); const j = g.exports; export { j as NcSettingsSelectGroup, j as default };