@christianriedl/media 1.0.173 → 1.0.174

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christianriedl/media",
3
- "version": "1.0.173",
3
+ "version": "1.0.174",
4
4
  "description": "RIC media interfaces",
5
5
 
6
6
  "main": "dist/index.js",
@@ -32,23 +32,35 @@
32
32
  }
33
33
  }
34
34
  async function addAuthor() {
35
+ if (!checkAuthor(author))
36
+ return;
35
37
  const id = await booksService.addAuthor(author);
36
38
  if (id > 0) {
37
39
  author.id = id;
38
40
  mustAddAuthor.value = false;
39
41
  }
42
+ else
43
+ alert (`AddAuthor - error ${id}`);
40
44
  }
41
45
  async function updateAuthor() {
46
+ if (!checkAuthor(author))
47
+ return;
42
48
  const rc = await booksService.updateAuthor(author);
43
49
  if (rc)
44
50
  mustUpdateAuthor.value = false;
51
+ else
52
+ alert ('UpdateAuthor - error');
45
53
  }
46
54
  async function deleteAuthor() {
55
+ if (!window.confirm(`Willst du ${author.surName} wirklich l�schen ?`))
56
+ return;
47
57
  const rc = await booksService.deleteAuthor(author.id);
48
58
  if (rc) {
49
59
  mustUpdateAuthor.value = false;
50
60
  initAuthor ("");
51
61
  }
62
+ else
63
+ alert (`DeleteAuthor ${author.id} - error`);
52
64
  }
53
65
  function initAuthor(surName: string) {
54
66
  author.id = 0;
@@ -59,7 +71,7 @@
59
71
  author.country = undefined;
60
72
  author.books = [];
61
73
  }
62
- async function getAuthor (id: number, withBooks: boolean) : Promise<boolean> {
74
+ async function getCurrentAuthor (id: number, withBooks: boolean) : Promise<boolean> {
63
75
  const authors = await booksService.getAuthors(undefined, undefined, withBooks, id);
64
76
  if (authors && authors.length > 0) {
65
77
  const a = authors[0];
@@ -77,13 +89,13 @@
77
89
  return false;
78
90
  }
79
91
  }
80
- async function nameChanged(arg: IAuthorShort | string) {
92
+ async function authorNameChanged(arg: IAuthorShort | string) {
81
93
  showCurrentBook.value = false;
82
94
  currentBook.value = { id: 0, authorId: 0, title: ""};
83
95
  mustAddAuthor.value = typeof arg == 'string';
84
96
  if (!mustAddAuthor.value) {
85
97
  const authorShort = arg as IAuthorShort;
86
- const rc = await getAuthor (authorShort.id, true);
98
+ const rc = await getCurrentAuthor (authorShort.id, true);
87
99
  }
88
100
  else {
89
101
  initAuthor (arg as string);
@@ -100,7 +112,7 @@
100
112
  await getAuthorDataFromAI(author.surName, author.givenName);
101
113
  }
102
114
  }
103
- async function addBook() {
115
+ async function addNewBook() {
104
116
  if (lastAllBooksId.value != author.id) {
105
117
  allBooks.value = await getAuthorBooksFromAI (author.surName, author.givenName, author.id);
106
118
  lastAllBooksId.value = author.id;
@@ -108,7 +120,7 @@
108
120
  newBook = reactive<IBook>({ id: 0, authorId: author.id, title: "", rating: 0 });
109
121
  showAddBookLine.value = true;
110
122
  }
111
- function cancelAddBook() {
123
+ function cancelAddNewBook() {
112
124
  showAddBookLine.value = false;
113
125
  }
114
126
  async function selectBook(id: number, func: () => void) {
@@ -141,8 +153,12 @@
141
153
 
142
154
  }
143
155
  async function deleteBook(id: number) {
156
+ if (!window.confirm(`Willst du das Buch wirklich l�schen ?`))
157
+ return;
144
158
  setBookChanged = () => {};
145
159
  const rc = await booksService.deleteBook (id);
160
+ if (!rc)
161
+ alert (`DeleteBook ${id}- error`);
146
162
  if (rc && author.books) {
147
163
  const idx = author.books.findIndex ((x) => x.id == id);
148
164
  if (idx >= 0)
@@ -150,8 +166,12 @@
150
166
  }
151
167
  }
152
168
  async function saveBook(book: IBook) {
169
+ if (!checkBook(book))
170
+ return;
153
171
  if (showAddBookLine.value) {
154
172
  const id = await booksService.addBook (book);
173
+ if (id < 0)
174
+ alert (`AddBook - error ${id}`);
155
175
  if (id > 0 && author.books) {
156
176
  book.id = id;
157
177
  author.books.splice (0, 0, book);
@@ -160,7 +180,47 @@
160
180
  }
161
181
  else {
162
182
  const rc = await booksService.updateBook (book);
183
+ if (!rc)
184
+ alert ('UpdateBook - error');
185
+ }
186
+ }
187
+ function checkAuthor (author: IAuthor): boolean {
188
+ if (!author.surName || !author.givenName) {
189
+ alert("Vor oder Nachname fehlt !");
190
+ return false;
191
+ }
192
+ if (author.surName.length >= 64 || author.givenName.length >= 64) {
193
+ alert("Vor oder Nachname zu lang (>64) !");
194
+ return false;
195
+ }
196
+ if (author.country && author.country.length >= 64) {
197
+ alert("Geburtsland zu lang (>64) !");
198
+ return false;
199
+ }
200
+ return true;
201
+ }
202
+ function checkBook (book: IBook): boolean {
203
+ if (!book.title) {
204
+ alert("Titel fehlt !");
205
+ return false;
206
+ }
207
+ if (book.title.length >= 256) {
208
+ alert("Titel zu lang (>256) !");
209
+ return false;
210
+ }
211
+ if (!book.authorId) {
212
+ alert("Autor fehlt !");
213
+ return false;
214
+ }
215
+ if (book.description && book.description.length >= 4000) {
216
+ alert("Beschreibung zu lang (>4000) !");
217
+ return false;
218
+ }
219
+ if (book.comment && book.comment.length >= 1024) {
220
+ alert("Kommentar zu lang (>1024) !");
221
+ return false;
163
222
  }
223
+ return true;
164
224
  }
165
225
  async function getAuthorDataFromAI(surName: string, givenName: string) {
166
226
  const schema =
@@ -273,7 +333,7 @@
273
333
  </v-row>
274
334
  <v-row dense align="center">
275
335
  <v-col cols="2">
276
- <v-combobox v-model="selected" :items="authors" item-value="id" item-title="sN" hide-details density="compact" single-line @update:modelValue="nameChanged"></v-combobox>
336
+ <v-combobox v-model="selected" :items="authors" item-value="id" item-title="sN" hide-details density="compact" single-line @update:modelValue="authorNameChanged"></v-combobox>
277
337
  </v-col>
278
338
  <v-col cols="2">
279
339
  <v-text-field v-model="author.givenName" hide-details density="compact" @update:modelValue="fieldChanged" @update:focused="givenNameFocused"></v-text-field>
@@ -299,15 +359,15 @@
299
359
  <v-col cols="2">JAHR</v-col>
300
360
  <v-col cols="2">RATING</v-col>
301
361
  <v-col v-if="author.id" cols="2">
302
- <v-btn v-if="!showAddBookLine" @click="addBook" append-icon="$plus">BOOK</v-btn>
303
- <v-btn v-if="showAddBookLine" @click="cancelAddBook" icon="$cancel"></v-btn>
362
+ <v-btn v-if="!showAddBookLine" @click="addNewBook" append-icon="$plus">BOOK</v-btn>
363
+ <v-btn v-if="showAddBookLine" @click="cancelAddNewBook" icon="$cancel"></v-btn>
304
364
  </v-col>
305
365
  </v-row>
306
366
  <book-line v-if="showAddBookLine" :book="newBook" :add="true" :allbooks="allBooks" @selectbook="selectBook" @deletebook="deleteBook" @savebook="saveBook"></book-line>
307
367
  <book-line v-for="book in author.books" :key="book.id" :book="book" @selectbook="selectBook" @deletebook="deleteBook" @savebook="saveBook"></book-line>
308
- <v-textarea v-if="showCurrentBook" clearable auto-grow variant="outlined" label="Description" v-model="currentBook.description" @update:modelValue="descriptionChanged">
368
+ <v-textarea v-if="showCurrentBook" class="pt-2"clearable auto-grow variant="outlined" label="Beschreibung" v-model="currentBook.description" @update:modelValue="descriptionChanged">
309
369
  </v-textarea>
310
- <v-textarea v-if="showCurrentBook" clearable auto-grow variant="outlined" label="Comment" v-model="currentBook.comment" @update:modelValue="descriptionChanged">
370
+ <v-textarea v-if="showCurrentBook" clearable auto-grow variant="outlined" label="Kommentar" v-model="currentBook.comment" @update:modelValue="descriptionChanged">
311
371
  </v-textarea>
312
372
  </v-defaults-provider>
313
373
  </v-container>