@fiduswriter/image-manager 0.1.13 → 0.1.16
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.
- package/dist/copyright_dialog/index.d.ts.map +1 -1
- package/dist/copyright_dialog/index.js +19 -20
- package/dist/copyright_dialog/index.js.map +1 -1
- package/dist/copyright_dialog/templates.d.ts +2 -2
- package/dist/copyright_dialog/templates.d.ts.map +1 -1
- package/dist/copyright_dialog/templates.js +3 -3
- package/dist/copyright_dialog/templates.js.map +1 -1
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +7 -8
- package/dist/database.js.map +1 -1
- package/dist/edit_dialog/index.d.ts.map +1 -1
- package/dist/edit_dialog/index.js +25 -23
- package/dist/edit_dialog/index.js.map +1 -1
- package/dist/edit_dialog/model.d.ts.map +1 -1
- package/dist/edit_dialog/model.js +14 -18
- package/dist/edit_dialog/model.js.map +1 -1
- package/dist/edit_dialog/templates.d.ts.map +1 -1
- package/dist/edit_dialog/templates.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/overview/categories.d.ts.map +1 -1
- package/dist/overview/categories.js +17 -20
- package/dist/overview/categories.js.map +1 -1
- package/dist/overview/index.d.ts.map +1 -1
- package/dist/overview/index.js +3 -2
- package/dist/overview/index.js.map +1 -1
- package/dist/overview/menu.d.ts.map +1 -1
- package/dist/overview/menu.js +13 -15
- package/dist/overview/menu.js.map +1 -1
- package/dist/selection_dialog/index.d.ts.map +1 -1
- package/dist/selection_dialog/index.js +22 -26
- package/dist/selection_dialog/index.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/copyright_dialog/index.ts +177 -186
- package/src/copyright_dialog/templates.ts +26 -19
- package/src/database.ts +61 -68
- package/src/edit_dialog/index.ts +261 -251
- package/src/edit_dialog/model.ts +220 -220
- package/src/edit_dialog/templates.ts +22 -22
- package/src/index.ts +5 -4
- package/src/overview/categories.ts +106 -116
- package/src/overview/index.ts +2 -2
- package/src/overview/menu.ts +77 -77
- package/src/selection_dialog/index.ts +197 -207
- package/src/types.ts +79 -65
|
@@ -1,128 +1,118 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "fwtoolkit"
|
|
9
|
-
import type {OverviewMenuDropdownItem} from "fwtoolkit/overview_menu"
|
|
2
|
+
Dialog,
|
|
3
|
+
activateWait,
|
|
4
|
+
addAlert,
|
|
5
|
+
deactivateWait,
|
|
6
|
+
gettext,
|
|
7
|
+
} from "fwtoolkit";
|
|
8
|
+
import type { OverviewMenuDropdownItem } from "fwtoolkit/overview_menu";
|
|
10
9
|
|
|
11
|
-
import {usermediaEditcategoriesTemplate} from "./templates.js"
|
|
12
|
-
import type {ImageOverview} from "./index.js"
|
|
13
|
-
import type {
|
|
14
|
-
ImageCategory,
|
|
15
|
-
SaveCategoriesRequest,
|
|
16
|
-
SaveCategoriesResponse
|
|
17
|
-
} from "../types.js"
|
|
10
|
+
import { usermediaEditcategoriesTemplate } from "./templates.js";
|
|
11
|
+
import type { ImageOverview } from "./index.js";
|
|
12
|
+
import type { ImageCategory, SaveCategoriesRequest } from "../types.js";
|
|
18
13
|
|
|
19
14
|
export class ImageOverviewCategories {
|
|
20
|
-
|
|
15
|
+
imageOverview: ImageOverview;
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
constructor(imageOverview: ImageOverview) {
|
|
18
|
+
this.imageOverview = imageOverview;
|
|
19
|
+
imageOverview.mod.categories = this;
|
|
20
|
+
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
//save changes or create a new category
|
|
23
|
+
saveCategories(cats: SaveCategoriesRequest): void {
|
|
24
|
+
activateWait();
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
this.imageOverview.app.apiConnectors.image
|
|
27
|
+
.saveCategories(cats)
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
addAlert("error", gettext("Could not update categories"));
|
|
30
|
+
deactivateWait();
|
|
31
|
+
throw error;
|
|
32
|
+
})
|
|
33
|
+
.then((response) => {
|
|
34
|
+
this.imageOverview.app.imageDB.cats = response.entries;
|
|
35
|
+
this.setImageCategoryList(response.entries);
|
|
36
|
+
addAlert("success", gettext("The categories have been updated"));
|
|
37
|
+
deactivateWait();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
catSelector.content = catSelector.content.filter(
|
|
55
|
-
cat => cat.type !== "category"
|
|
56
|
-
)
|
|
57
|
-
catSelector.content = catSelector.content.concat(
|
|
58
|
-
imageCategories.map(cat => ({
|
|
59
|
-
type: "category",
|
|
60
|
-
title: cat.category_title,
|
|
61
|
-
action: (_overview: unknown) => {
|
|
62
|
-
const trs = document.querySelectorAll(
|
|
63
|
-
"#imagelist > tbody > tr"
|
|
64
|
-
)
|
|
65
|
-
trs.forEach(tr => {
|
|
66
|
-
const imageCell = tr.querySelector(".fw-usermedia-image")
|
|
67
|
-
if (
|
|
68
|
-
imageCell &&
|
|
69
|
-
imageCell.classList.contains(`cat_${cat.id}`)
|
|
70
|
-
) {
|
|
71
|
-
;(tr as HTMLElement).style.display = ""
|
|
72
|
-
} else {
|
|
73
|
-
;(tr as HTMLElement).style.display = "none"
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
}))
|
|
78
|
-
)
|
|
79
|
-
this.imageOverview.menu.update()
|
|
41
|
+
setImageCategoryList(imageCategories: ImageCategory[]): void {
|
|
42
|
+
const catSelector = this.imageOverview.menu.model.content.find(
|
|
43
|
+
(menuItem): menuItem is OverviewMenuDropdownItem =>
|
|
44
|
+
menuItem.id === "cat_selector",
|
|
45
|
+
);
|
|
46
|
+
if (!catSelector) {
|
|
47
|
+
return;
|
|
80
48
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const input = el as HTMLInputElement
|
|
97
|
-
const thisVal = input.value.trim()
|
|
98
|
-
let thisId: string | number = input.dataset.id || "0"
|
|
99
|
-
if ("undefined" == typeof thisId) {
|
|
100
|
-
thisId = 0
|
|
101
|
-
}
|
|
102
|
-
if ("" !== thisVal) {
|
|
103
|
-
cats.ids.push(thisId)
|
|
104
|
-
cats.titles.push(thisVal)
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
this.saveCategories(cats)
|
|
108
|
-
dialog.close()
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
type: "cancel" as const
|
|
49
|
+
catSelector.content = catSelector.content.filter(
|
|
50
|
+
(cat) => cat.type !== "category",
|
|
51
|
+
);
|
|
52
|
+
catSelector.content = catSelector.content.concat(
|
|
53
|
+
imageCategories.map((cat) => ({
|
|
54
|
+
type: "category",
|
|
55
|
+
title: cat.category_title,
|
|
56
|
+
action: (_overview: unknown) => {
|
|
57
|
+
const trs = document.querySelectorAll("#imagelist > tbody > tr");
|
|
58
|
+
trs.forEach((tr) => {
|
|
59
|
+
const imageCell = tr.querySelector(".fw-usermedia-image");
|
|
60
|
+
if (imageCell && imageCell.classList.contains(`cat_${cat.id}`)) {
|
|
61
|
+
(tr as HTMLElement).style.display = "";
|
|
62
|
+
} else {
|
|
63
|
+
(tr as HTMLElement).style.display = "none";
|
|
113
64
|
}
|
|
114
|
-
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
})),
|
|
68
|
+
);
|
|
69
|
+
this.imageOverview.menu.update();
|
|
70
|
+
}
|
|
115
71
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
72
|
+
//open a dialog for editing categories
|
|
73
|
+
editCategoryDialog(): void {
|
|
74
|
+
const buttons = [
|
|
75
|
+
{
|
|
76
|
+
text: gettext("Submit"),
|
|
77
|
+
classes: "fw-dark",
|
|
78
|
+
click: () => {
|
|
79
|
+
const cats: SaveCategoriesRequest = {
|
|
80
|
+
ids: [],
|
|
81
|
+
titles: [],
|
|
82
|
+
};
|
|
83
|
+
document
|
|
84
|
+
.querySelectorAll("#edit-categories .category-form")
|
|
85
|
+
.forEach((el) => {
|
|
86
|
+
const input = el as HTMLInputElement;
|
|
87
|
+
const thisVal = input.value.trim();
|
|
88
|
+
let thisId: string | number = input.dataset.id || "0";
|
|
89
|
+
if ("undefined" == typeof thisId) {
|
|
90
|
+
thisId = 0;
|
|
91
|
+
}
|
|
92
|
+
if ("" !== thisVal) {
|
|
93
|
+
cats.ids.push(thisId);
|
|
94
|
+
cats.titles.push(thisVal);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.saveCategories(cats);
|
|
98
|
+
dialog.close();
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: "cancel" as const,
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const dialog = new Dialog({
|
|
107
|
+
id: "edit-categories",
|
|
108
|
+
title: gettext("Edit Categories"),
|
|
109
|
+
body: usermediaEditcategoriesTemplate({
|
|
110
|
+
categories: this.imageOverview.app.imageDB.cats,
|
|
111
|
+
}),
|
|
112
|
+
width: 350,
|
|
113
|
+
height: 350,
|
|
114
|
+
buttons,
|
|
115
|
+
});
|
|
116
|
+
dialog.open();
|
|
117
|
+
}
|
|
128
118
|
}
|
package/src/overview/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
gettext,
|
|
12
12
|
isActivationEvent,
|
|
13
13
|
localizeDate,
|
|
14
|
-
post,
|
|
15
14
|
setDocTitle,
|
|
16
15
|
staticUrl,
|
|
17
16
|
whenReady,
|
|
@@ -157,7 +156,8 @@ export class ImageOverview {
|
|
|
157
156
|
return;
|
|
158
157
|
}
|
|
159
158
|
activateWait();
|
|
160
|
-
|
|
159
|
+
this.app.apiConnectors.image
|
|
160
|
+
.deleteImages(numericIds)
|
|
161
161
|
.catch((error) => {
|
|
162
162
|
addAlert("error", gettext("The image(s) could not be deleted"));
|
|
163
163
|
deactivateWait();
|
package/src/overview/menu.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import {gettext} from "fwtoolkit"
|
|
2
|
-
import type {ContentMenuInit} from "fwtoolkit/content_menu"
|
|
3
|
-
import type {OverviewMenuModel} from "fwtoolkit/overview_menu"
|
|
1
|
+
import { gettext } from "fwtoolkit";
|
|
2
|
+
import type { ContentMenuInit } from "fwtoolkit/content_menu";
|
|
3
|
+
import type { OverviewMenuModel } from "fwtoolkit/overview_menu";
|
|
4
4
|
|
|
5
|
-
import type {ImageManagerPage} from "../types.js"
|
|
6
|
-
import type {ImageOverview} from "./index.js"
|
|
5
|
+
import type { ImageManagerPage } from "../types.js";
|
|
6
|
+
import type { ImageOverview } from "./index.js";
|
|
7
7
|
|
|
8
8
|
export const bulkMenuModel = (): ContentMenuInit => ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
disabled: (overview: unknown) =>
|
|
20
|
-
!(overview as ImageOverview).getSelected().length ||
|
|
21
|
-
(overview as ImageOverview).app.isOffline()
|
|
9
|
+
content: [
|
|
10
|
+
{
|
|
11
|
+
title: gettext("Delete selected"),
|
|
12
|
+
tooltip: gettext("Delete selected images."),
|
|
13
|
+
action: (overview: unknown) => {
|
|
14
|
+
const ids = (overview as ImageOverview).getSelected();
|
|
15
|
+
if (ids.length) {
|
|
16
|
+
(overview as ImageOverview).deleteImageDialog(ids);
|
|
22
17
|
}
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
},
|
|
19
|
+
disabled: (overview: unknown) =>
|
|
20
|
+
!(overview as ImageOverview).getSelected().length ||
|
|
21
|
+
(overview as ImageOverview).app.isOffline(),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
25
|
|
|
26
26
|
export const menuModel = (): OverviewMenuModel => ({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
title: gettext("All categories"),
|
|
35
|
-
action: (_overview: unknown) => {
|
|
36
|
-
const trs = document.querySelectorAll(
|
|
37
|
-
"#imagelist > tbody > tr"
|
|
38
|
-
)
|
|
39
|
-
trs.forEach(tr => ((tr as HTMLElement).style.display = ""))
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
order: 1
|
|
44
|
-
},
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: "dropdown",
|
|
30
|
+
id: "cat_selector",
|
|
31
|
+
keys: "Alt-c",
|
|
32
|
+
content: [
|
|
45
33
|
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
order: 2,
|
|
52
|
-
disabled: (overview: unknown) => (overview as ImageOverview).app.isOffline()
|
|
34
|
+
title: gettext("All categories"),
|
|
35
|
+
action: (_overview: unknown) => {
|
|
36
|
+
const trs = document.querySelectorAll("#imagelist > tbody > tr");
|
|
37
|
+
trs.forEach((tr) => ((tr as HTMLElement).style.display = ""));
|
|
38
|
+
},
|
|
53
39
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
40
|
+
],
|
|
41
|
+
order: 1,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
title: gettext("Edit categories"),
|
|
46
|
+
keys: "Alt-e",
|
|
47
|
+
action: (overview: unknown) =>
|
|
48
|
+
(overview as ImageOverview).mod.categories!.editCategoryDialog(),
|
|
49
|
+
order: 2,
|
|
50
|
+
disabled: (overview: unknown) =>
|
|
51
|
+
(overview as ImageOverview).app.isOffline(),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
title: gettext("Upload new image"),
|
|
56
|
+
keys: "Alt-u",
|
|
57
|
+
action: (overview: unknown) => {
|
|
58
|
+
import("../edit_dialog/index.js").then(({ ImageEditDialog }) => {
|
|
59
|
+
const imageUpload = new ImageEditDialog(
|
|
60
|
+
(overview as ImageOverview).app.imageDB,
|
|
61
|
+
false,
|
|
62
|
+
overview as ImageManagerPage,
|
|
63
|
+
);
|
|
64
|
+
imageUpload.init().then((imageId) => {
|
|
65
|
+
if (imageId) {
|
|
66
|
+
(overview as ImageOverview).updateTable([imageId]);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
order: 3,
|
|
72
|
+
disabled: (overview: unknown) =>
|
|
73
|
+
(overview as ImageOverview).app.isOffline(),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "search",
|
|
77
|
+
icon: "search",
|
|
78
|
+
title: gettext("Search images"),
|
|
79
|
+
keys: "Alt-s",
|
|
80
|
+
input: (overview: unknown, text: string) =>
|
|
81
|
+
(overview as ImageOverview).table!.search(text),
|
|
82
|
+
order: 4,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|