View | Details | Raw Unified | Return to bug 39320
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ModuleDashboard/Widgets/ERMCounts.vue (-50 / +14 lines)
Lines 8-21 Link Here
8
                            v-if="def.page && !def.loading"
8
                            v-if="def.page && !def.loading"
9
                            :to="{ name: def.page }"
9
                            :to="{ name: def.page }"
10
                        >
10
                        >
11
                            {{ createCountText(def) }}
11
                            {{ def.i18nLabel(def.count) }}
12
                        </router-link>
12
                        </router-link>
13
                        <span v-else class="inactive-link">
13
                        <span v-else class="inactive-link">
14
                            <div
14
                            <div
15
                                class="spinner-border spinner-border-sm"
15
                                class="spinner-border spinner-border-sm"
16
                                role="status"
16
                                role="status"
17
                            ></div>
17
                            ></div>
18
                            {{ createCountText(def) }}
18
                            {{ def.i18nLabel(def.count) }}
19
                        </span>
19
                        </span>
20
                    </strong>
20
                    </strong>
21
                </li>
21
                </li>
Lines 58-63 export default { Link Here
58
            {
58
            {
59
                page: "AgreementsList",
59
                page: "AgreementsList",
60
                name: "agreements_count",
60
                name: "agreements_count",
61
                fetchCount: () => APIClient.erm.agreements.count(),
61
                i18nLabel: count =>
62
                i18nLabel: count =>
62
                    __nx("{count} agreement", "{count} agreements", count, {
63
                    __nx("{count} agreement", "{count} agreements", count, {
63
                        count,
64
                        count,
Lines 68-73 export default { Link Here
68
            {
69
            {
69
                page: "LicensesList",
70
                page: "LicensesList",
70
                name: "licenses_count",
71
                name: "licenses_count",
72
                fetchCount: () => APIClient.erm.licenses.count(),
71
                i18nLabel: count =>
73
                i18nLabel: count =>
72
                    __nx("{count} license", "{count} licenses", count, {
74
                    __nx("{count} license", "{count} licenses", count, {
73
                        count,
75
                        count,
Lines 78-83 export default { Link Here
78
            {
80
            {
79
                page: "EHoldingsLocalPackagesList",
81
                page: "EHoldingsLocalPackagesList",
80
                name: "eholdings_packages_count",
82
                name: "eholdings_packages_count",
83
                fetchCount: () => APIClient.erm.localPackages.count(),
81
                i18nLabel: count =>
84
                i18nLabel: count =>
82
                    __nx(
85
                    __nx(
83
                        "{count} local package",
86
                        "{count} local package",
Lines 91-96 export default { Link Here
91
            {
94
            {
92
                page: "EHoldingsLocalTitlesList",
95
                page: "EHoldingsLocalTitlesList",
93
                name: "eholdings_titles_count",
96
                name: "eholdings_titles_count",
97
                fetchCount: () => APIClient.erm.localTitles.count(),
94
                i18nLabel: count =>
98
                i18nLabel: count =>
95
                    __nx("{count} local title", "{count} local titles", count, {
99
                    __nx("{count} local title", "{count} local titles", count, {
96
                        count,
100
                        count,
Lines 101-106 export default { Link Here
101
            {
105
            {
102
                page: "UsageStatisticsDataProvidersList",
106
                page: "UsageStatisticsDataProvidersList",
103
                name: "usage_data_providers_count",
107
                name: "usage_data_providers_count",
108
                fetchCount: () => APIClient.erm.usage_data_providers.count(),
104
                i18nLabel: count =>
109
                i18nLabel: count =>
105
                    __nx(
110
                    __nx(
106
                        "{count} usage data provider",
111
                        "{count} usage data provider",
Lines 113-165 export default { Link Here
113
            },
118
            },
114
        ]);
119
        ]);
115
120
116
        const createCountText = definition => {
117
            return definition.i18nLabel(definition.count);
118
        };
119
120
        async function getCounts() {
121
        async function getCounts() {
121
            try {
122
            await Promise.all(
122
                const endpoints = [
123
                countDefinitions.map(async definition => {
123
                    {
124
                    const response = await definition.fetchCount();
124
                        name: "agreements_count",
125
                    definition.count = response;
125
                        endpoint: APIClient.erm.agreements.count(),
126
                    definition.loading = false;
126
                    },
127
                })
127
                    {
128
            );
128
                        name: "licenses_count",
129
                        endpoint: APIClient.erm.licenses.count(),
130
                    },
131
                    {
132
                        name: "eholdings_packages_count",
133
                        endpoint: APIClient.erm.localPackages.count(),
134
                    },
135
                    {
136
                        name: "eholdings_titles_count",
137
                        endpoint: APIClient.erm.localTitles.count(),
138
                    },
139
                    {
140
                        name: "usage_data_providers_count",
141
                        endpoint: APIClient.erm.usage_data_providers.count(),
142
                    },
143
                ];
144
145
                endpoints.forEach(({ name, endpoint }) => {
146
                    endpoint
147
                        .then(response => {
148
                            const definition = countDefinitions.find(
149
                                i => i.name === name
150
                            );
151
                            if (definition) {
152
                                definition.count = response;
153
                                definition.loading = false;
154
                            }
155
                        })
156
                        .catch(error => {
157
                            console.error(`Error fetching ${name}:`, error);
158
                        });
159
                });
160
            } catch (error) {
161
                console.error(error);
162
            }
163
        }
129
        }
164
130
165
        baseWidget.onDashboardMounted(() => {
131
        baseWidget.onDashboardMounted(() => {
Lines 172-178 export default { Link Here
172
138
173
        return {
139
        return {
174
            ...baseWidget,
140
            ...baseWidget,
175
            createCountText,
176
            countDefinitions,
141
            countDefinitions,
177
            goToPage,
142
            goToPage,
178
        };
143
        };
179
- 

Return to bug 39320