@nextcloud/vue
Version:
Nextcloud vue components
69 lines (68 loc) • 3.68 kB
JavaScript
import "../assets/index53.css";
import o from "@nextcloud/axios";
import { generateOcsUrl as a } from "@nextcloud/router";
import l from "./NcButton.mjs";
import { t } from "../chunks/l10n-9a5a6afc.mjs";
import { n as i } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs";
const n = { name: "NcResource", components: { NcButton: l }, props: { icon: { type: String, required: !0 }, name: { type: String, required: !0 }, url: { type: String, required: !0 } }, data() {
return { labelTranslated: t('Open link to "{resourceName}"', { resourceName: this.name }) };
}, methods: { t } };
var u = function() {
var e = this, r = e._self._c;
return r("li", { staticClass: "resource" }, [r("NcButton", { staticClass: "resource__button", attrs: { "aria-label": e.labelTranslated, type: "tertiary", href: e.url }, scopedSlots: e._u([{ key: "icon", fn: function() {
return [r("div", { staticClass: "resource__icon" }, [r("img", { attrs: { src: e.icon } })])];
}, proxy: !0 }]) }, [e._v(" " + e._s(e.name) + " ")])], 1);
}, c = [], d = i(n, u, c, !1, null, "1a960bef", null, null);
const h = d.exports;
const p = { name: "NcRelatedResourcesPanel", components: { NcResource: h }, props: { providerId: { type: String, default: null }, itemId: { type: [String, Number], default: null }, fileInfo: { type: Object, default: null } }, emits: ["has-error", "has-resources"], data() {
var e;
return { appEnabled: ((e = OC == null ? void 0 : OC.appswebroots) == null ? void 0 : e.related_resources) !== void 0, headerTranslated: t("Related resources"), loading: !1, error: null, resources: [] };
}, computed: { isVisible() {
var e;
return this.loading ? !1 : (e = this.error) != null ? e : this.resources.length > 0;
}, description() {
return this.error ? t("Error getting related resources. Please contact your system administrator if you have any questions.") : t("Anything shared with the same group of people will show up here");
}, hasResourceInfo() {
return this.providerId !== null && this.itemId !== null || this.fileInfo !== null;
}, isFiles() {
var e;
return ((e = this.fileInfo) == null ? void 0 : e.id) !== void 0;
}, url() {
let e = null, r = null;
return this.isFiles ? (e = "files", r = this.fileInfo.id) : (e = this.providerId, r = this.itemId), a("/apps/related_resources/related/{providerId}?itemId={itemId}&format=json", { providerId: e, itemId: r });
} }, watch: { providerId() {
this.fetchRelatedResources();
}, itemId() {
this.fetchRelatedResources();
}, fileInfo() {
this.fetchRelatedResources();
}, error(e) {
this.$emit("has-error", !!e);
}, resources(e) {
this.$emit("has-resources", e.length > 0);
} }, created() {
this.fetchRelatedResources();
}, methods: { t, async fetchRelatedResources() {
var e;
if (!(!this.appEnabled || !this.hasResourceInfo)) {
this.loading = !0, this.error = null, this.resources = [];
try {
const r = await o.get(this.url);
this.resources = (e = r.data.ocs) == null ? void 0 : e.data;
} catch (r) {
this.error = r, console.error(r);
} finally {
this.loading = !1;
}
}
} } };
var f = function() {
var e = this, r = e._self._c;
return e.appEnabled && e.isVisible ? r("div", { staticClass: "related-resources" }, [r("div", { staticClass: "related-resources__header" }, [r("h5", [e._v(e._s(e.headerTranslated))]), r("p", [e._v(e._s(e.description))])]), e._l(e.resources, function(s) {
return r("NcResource", { key: s.itemId, staticClass: "related-resources__entry", attrs: { icon: s.icon, name: s.title, url: s.url } });
})], 2) : e._e();
}, m = [], _ = i(p, f, m, !1, null, "235fc8aa", null, null);
const N = _.exports;
export {
N as default
};