@fiduswriter/image-manager 0.1.13 → 0.1.14

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.
Files changed (48) hide show
  1. package/dist/copyright_dialog/index.d.ts.map +1 -1
  2. package/dist/copyright_dialog/index.js +19 -20
  3. package/dist/copyright_dialog/index.js.map +1 -1
  4. package/dist/copyright_dialog/templates.d.ts +2 -2
  5. package/dist/copyright_dialog/templates.d.ts.map +1 -1
  6. package/dist/copyright_dialog/templates.js +3 -3
  7. package/dist/copyright_dialog/templates.js.map +1 -1
  8. package/dist/database.d.ts.map +1 -1
  9. package/dist/database.js +7 -8
  10. package/dist/database.js.map +1 -1
  11. package/dist/edit_dialog/index.d.ts.map +1 -1
  12. package/dist/edit_dialog/index.js +25 -23
  13. package/dist/edit_dialog/index.js.map +1 -1
  14. package/dist/edit_dialog/model.d.ts.map +1 -1
  15. package/dist/edit_dialog/model.js +14 -18
  16. package/dist/edit_dialog/model.js.map +1 -1
  17. package/dist/edit_dialog/templates.d.ts.map +1 -1
  18. package/dist/edit_dialog/templates.js.map +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/overview/categories.d.ts.map +1 -1
  23. package/dist/overview/categories.js +17 -20
  24. package/dist/overview/categories.js.map +1 -1
  25. package/dist/overview/index.d.ts.map +1 -1
  26. package/dist/overview/index.js +3 -2
  27. package/dist/overview/index.js.map +1 -1
  28. package/dist/overview/menu.d.ts.map +1 -1
  29. package/dist/overview/menu.js +13 -15
  30. package/dist/overview/menu.js.map +1 -1
  31. package/dist/selection_dialog/index.d.ts.map +1 -1
  32. package/dist/selection_dialog/index.js +22 -26
  33. package/dist/selection_dialog/index.js.map +1 -1
  34. package/dist/types.d.ts +10 -0
  35. package/dist/types.d.ts.map +1 -1
  36. package/package.json +8 -4
  37. package/src/copyright_dialog/index.ts +177 -186
  38. package/src/copyright_dialog/templates.ts +26 -19
  39. package/src/database.ts +61 -68
  40. package/src/edit_dialog/index.ts +261 -251
  41. package/src/edit_dialog/model.ts +220 -220
  42. package/src/edit_dialog/templates.ts +22 -22
  43. package/src/index.ts +5 -4
  44. package/src/overview/categories.ts +106 -116
  45. package/src/overview/index.ts +2 -2
  46. package/src/overview/menu.ts +77 -77
  47. package/src/selection_dialog/index.ts +197 -207
  48. package/src/types.ts +79 -65
@@ -1,128 +1,118 @@
1
1
  import {
2
- Dialog,
3
- activateWait,
4
- addAlert,
5
- deactivateWait,
6
- gettext,
7
- postJson
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
- imageOverview: ImageOverview
15
+ imageOverview: ImageOverview;
21
16
 
22
- constructor(imageOverview: ImageOverview) {
23
- this.imageOverview = imageOverview
24
- imageOverview.mod.categories = this
25
- }
17
+ constructor(imageOverview: ImageOverview) {
18
+ this.imageOverview = imageOverview;
19
+ imageOverview.mod.categories = this;
20
+ }
26
21
 
27
- //save changes or create a new category
28
- saveCategories(cats: SaveCategoriesRequest): void {
29
- activateWait()
22
+ //save changes or create a new category
23
+ saveCategories(cats: SaveCategoriesRequest): void {
24
+ activateWait();
30
25
 
31
- postJson("/api/usermedia/save_category/", cats as unknown as Record<string, unknown>)
32
- .catch(error => {
33
- addAlert("error", gettext("Could not update categories"))
34
- deactivateWait()
35
- throw error
36
- })
37
- .then(({json}) => {
38
- const response = json as SaveCategoriesResponse
39
- this.imageOverview.app.imageDB.cats = response.entries
40
- this.setImageCategoryList(response.entries)
41
- addAlert("success", gettext("The categories have been updated"))
42
- deactivateWait()
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
- setImageCategoryList(imageCategories: ImageCategory[]): void {
47
- const catSelector = this.imageOverview.menu.model.content.find(
48
- (menuItem): menuItem is OverviewMenuDropdownItem =>
49
- menuItem.id === "cat_selector"
50
- )
51
- if (!catSelector) {
52
- return
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
- //open a dialog for editing categories
83
- editCategoryDialog(): void {
84
- const buttons = [
85
- {
86
- text: gettext("Submit"),
87
- classes: "fw-dark",
88
- click: () => {
89
- const cats: SaveCategoriesRequest = {
90
- ids: [],
91
- titles: []
92
- }
93
- document
94
- .querySelectorAll("#edit-categories .category-form")
95
- .forEach(el => {
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
- const dialog = new Dialog({
117
- id: "edit-categories",
118
- title: gettext("Edit Categories"),
119
- body: usermediaEditcategoriesTemplate({
120
- categories: this.imageOverview.app.imageDB.cats
121
- }),
122
- width: 350,
123
- height: 350,
124
- buttons
125
- })
126
- dialog.open()
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
  }
@@ -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
- post("/api/usermedia/delete/", { ids: numericIds })
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();
@@ -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
- 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)
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
- content: [
28
- {
29
- type: "dropdown",
30
- id: "cat_selector",
31
- keys: "Alt-c",
32
- content: [
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
- type: "text",
47
- title: gettext("Edit categories"),
48
- keys: "Alt-e",
49
- action: (overview: unknown) =>
50
- (overview as ImageOverview).mod.categories!.editCategoryDialog(),
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
- type: "text",
56
- title: gettext("Upload new image"),
57
- keys: "Alt-u",
58
- action: (overview: unknown) => {
59
- import("../edit_dialog/index.js").then(({ImageEditDialog}) => {
60
- const imageUpload = new ImageEditDialog(
61
- (overview as ImageOverview).app.imageDB,
62
- false,
63
- overview as ImageManagerPage
64
- )
65
- imageUpload.init().then(imageId => {
66
- if (imageId) {
67
- ;(overview as ImageOverview).updateTable([imageId])
68
- }
69
- })
70
- })
71
- },
72
- order: 3,
73
- disabled: (overview: unknown) => (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
- })
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
+ });