Skip to content

Commit 77dc15b

Browse files
authored
Merge pull request #13 from xnodeoncode/clean-up
See changes.md for revisions list.
2 parents c9dff7a + 39e261d commit 77dc15b

15 files changed

+385
-391
lines changed

changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@
1616
#### June 21, 2024
1717

1818
- Implement versioning folders to maintain access to history.
19+
20+
#### June 22, 2024
21+
22+
- Code cleanup - removed unused artifacts and completed documentation.
23+
- Implemented StorageItem class.

v1/js/itemStore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class ItemStore {
4040
let id = Date.now();
4141
return id;
4242
}
43+
4344
/********************************************************************
4445
* Finds item by id.
4546
*******************************************************************/

v2/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
<body>
2121
<div id="container"></div>
22+
<!--
23+
The main must be declared as a module via the type attribute.
24+
This ensures that the imports will work.
25+
-->
2226
<script type="module" src="./js/app.js"></script>
2327
</body>
2428
</html>

v2/js/app.js

Lines changed: 84 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,69 @@
1-
// App Interface (MVC).
2-
3-
/*
4-
The model class can be imported for a type driven UI, but this is optional.
5-
The datastore does not use model properties for persistence.
6-
All items are added to an item collection.
7-
The item collection is persisted as a JSON array, regardless of the persistence type selected.
8-
*/
1+
// Bookshelf App Interface (MVC).
2+
3+
/************************************************************************************
4+
* The model class can be imported for a type driven UI, but this is optional.
5+
* The datastore does not use model properties for persistence.
6+
* All items are added to an item collection.
7+
* The item collection is persisted as a JSON array, regardless of the persistence type selected.
8+
***********************************************************************************/
99
import { Book } from "./book.js";
1010

11-
/*
12-
The ItemStore module is required to manage the collection.
13-
The DatabaseSettings module is required to override the default persistence settings.
14-
See the example implementations below.
15-
*/
11+
/************************************************************************************
12+
* The ItemStore module is required to manage the collection.
13+
* The DatabaseSettings module is required to override the default persistence settings.
14+
* See the example implementations below.
15+
************************************************************************************/
1616
import { ItemStore } from "./itemStore.js";
1717

18-
/*
19-
Persistence types is an enum of the browser supported persistence methods.
20-
This module can be imported for strongly typed declarations but this is optional.
21-
The persistence types can be passed directly as strings.
22-
*/
18+
/*************************************************************************************
19+
* Persistence types is an enum of the browser supported persistence methods.
20+
* This module can be imported for strongly typed declarations but this is optional.
21+
* The persistence types can be passed directly as strings.
22+
************************************************************************************/
2323
import { PersistenceTypes } from "./services/dataService.js";
2424

25-
/***************************************************************************************
26-
Use this declaration to create a item store to manage the collection using default settings.
27-
The collection will be in memory only and deleted upon page refresh or when the browser window is closed.
28-
****************************************************************************************/
25+
/*************************************************************************************
26+
* The DatabaseSettings class can be used to override the default persistence settings.
27+
* Properties such as database name, key field, and persistence type can all be
28+
* customized using valid options.
29+
*************************************************************************************/
30+
import { DatabaseSettings } from "./services/databaseSettings.js";
2931

32+
/*************************************************************************************
33+
* Use this declaration to create a item store to manage the collection
34+
* using default settings.
35+
* The collection will be in memory only and deleted upon page refresh or
36+
* when the browser window is closed.
37+
************************************************************************************/
3038
//const bookDepot = new ItemStore();
3139

3240
/*************************************************************************************
33-
Use this declaration to create a item store to manage the collection without persistence.
34-
When the usePersistenceStore parameter is set to false,
35-
the collection will be in memory only and deleted upon page refresh or when the browser window is closed.
36-
*************************************************************************************/
37-
41+
* Use this declaration to create a item store to manage the collection without persistence.
42+
* When the usePersistenceStore parameter is set to false,
43+
* the collection will be in memory only and deleted upon page refresh or
44+
* when the browser window is closed.
45+
*************************************************************************************/
3846
//const bookDepot = new ItemStore("MyBookStore", false);
3947

40-
/*************************************************************************************
41-
Use this declaration to create an item store to manage the collection with default persistence settings.
42-
This implementation will use cookie storage by default.
43-
The collection will be stored with the browser's cookie until the cookie expires or is deleted.
44-
**************************************************************************************/
45-
46-
const bookDepot = new ItemStore("MyBookStore", true);
47-
4848
/**************************************************************************************
49-
An instace of the DatabaseSettings module is required to override the default settings.
50-
Settings such as the database name, database version, table name, as well as key field can be overridden.
51-
This is also where the persistence type can be changed from cookie storage to another option.
52-
This code is ignored when the ItemStore.usePersistence property is set to false.
53-
***************************************************************************************/
49+
* Use this declaration to create an item store to manage the collection with
50+
* default persistence settings.
51+
* This implementation will use cookie storage by default.
52+
* The collection will be stored with the browser's cookie until the cookie expires or
53+
* is deleted.
54+
**************************************************************************************/
55+
const bookDepot = new ItemStore("MyBookStore", true);
5456

55-
//Initialize the persistence store by passing in database settings.
57+
/***************************************************************************************
58+
* An instace of the DatabaseSettings module is required to override the default settings.
59+
* Settings such as the database name, database version, table name, as well as key field
60+
* can be overridden.
61+
* This is also where the persistence type can be changed from cookie storage to another option.
62+
* This code is ignored when the ItemStore.usePersistence property is set to false.
63+
***************************************************************************************/
64+
65+
//Initialize the data store by passing in a DatabaseSettings object.
5666
//The persistence types enum can be used for a strongly typed list of supported types.
57-
import { DatabaseSettings } from "./services/databaseSettings.js";
5867
let databaseSettings = new DatabaseSettings(
5968
"MyBookStore",
6069
1,
@@ -64,12 +73,14 @@ let databaseSettings = new DatabaseSettings(
6473
);
6574
bookDepot.initializeDataStore(databaseSettings);
6675

67-
/**************************************************************************************/
68-
69-
// new page title
76+
/**************************************************************************************
77+
* New page title
78+
**************************************************************************************/
7079
const pageTitle = "Javascript - Bookshelf";
7180

72-
// HTML markup to display the book collection.
81+
/***************************************************************************************
82+
* HTML markup to display the book collection.
83+
***************************************************************************************/
7384
const markUp =
7485
"<header>" +
7586
"<h1>Bookshelf</h1>" +
@@ -102,7 +113,9 @@ const markUp =
102113
"</div>" +
103114
"</div>";
104115

105-
// initialize the page.
116+
/**********************************************************************************
117+
* initialize the page.
118+
**********************************************************************************/
106119
(function () {
107120
// set page title
108121
document.title = pageTitle;
@@ -135,9 +148,9 @@ const markUp =
135148
resetForm();
136149
})();
137150

138-
/*
139-
Clear all form values.
140-
*/
151+
/********************************************************************************
152+
* Clear all form values.
153+
********************************************************************************/
141154
function resetForm() {
142155
// get all inputs
143156
var inputs = document.querySelectorAll(
@@ -158,9 +171,10 @@ function resetForm() {
158171
// set focus on the first input
159172
document.getElementById("new-book-title").focus();
160173
}
161-
/*
162-
Update book list display
163-
*/
174+
175+
/***********************************************************************************
176+
* Update book list display
177+
***********************************************************************************/
164178
function updateListDisplay() {
165179
// access the book container
166180
var bookList = document.getElementById("book-list");
@@ -254,9 +268,9 @@ function updateListDisplay() {
254268
}
255269
}
256270

257-
/*
258-
Save a new book from the form values. This could be pushed back to the book depot, but I kind of like it sitting in this "controller".
259-
*/
271+
/***************************************************************************************
272+
* Save a new book using form values.
273+
***************************************************************************************/
260274
function saveBook() {
261275
// get values from the html input elements.
262276
let title = document.getElementById("new-book-title").value;
@@ -296,9 +310,10 @@ function saveBook() {
296310
resetForm();
297311
}
298312

299-
/*
300-
Delete a book from the repository
301-
*/
313+
/******************************************************************************************
314+
* Delete a book from the repository
315+
* bookId|int: The id for the item to be deleted.
316+
******************************************************************************************/
302317
function deleteBook(bookId) {
303318
// remove the book by id.
304319
var b = bookDepot.removeBookById(bookId);
@@ -310,9 +325,10 @@ function deleteBook(bookId) {
310325
console.log(JSON.stringify(b));
311326
}
312327

313-
/*
314-
Update a single book
315-
*/
328+
/******************************************************************************************
329+
* Update book.
330+
* bookId|int: The id of the book to be updated.
331+
******************************************************************************************/
316332
function updateBook(bookId) {
317333
// find the book to be updated
318334
var book = bookDepot.getBookById(bookId);
@@ -324,18 +340,17 @@ function updateBook(bookId) {
324340
document.getElementById("new-book-id").value = book.id;
325341
}
326342

327-
/*
328-
Output all of the contents of the repository object to the console.
329-
*/
343+
/******************************************************************************************
344+
* Output the contents of the repository object to the console.
345+
******************************************************************************************/
330346
function displayCollection() {
331347
// display the repository in the console.
332348
console.log(bookDepot);
333349
}
334350

335-
/*
336-
Seed the repository with previously stored items if any.
337-
Update the display.
338-
*/
351+
/******************************************************************************************
352+
* Load any existing items from the repository and update the display.
353+
******************************************************************************************/
339354
async function seedTheRepository() {
340355
bookDepot.books = await bookDepot.retrieve();
341356
updateListDisplay();

v2/js/book.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/***********************************************************************
2+
* Book class
3+
* Title|string: The book title.
4+
* Author|string: The book's author.
5+
* NumberOfPages|int: The number of pages in the book.
6+
***********************************************************************/
17
export class Book {
28
constructor(title, author, numberOfPages) {
39
this.id = 0;
@@ -8,18 +14,24 @@ export class Book {
814
this.modifiedOn = this.getDate();
915
}
1016

11-
// get current date as a locale string
17+
/***********************************************************************
18+
* Gets current date as a locale string
19+
***********************************************************************/
1220
getDate() {
1321
let today = new Date();
1422
return today.toLocaleDateString();
1523
}
1624

17-
// Returns book details to the.
25+
/***********************************************************************
26+
* Returns|string: Book details.
27+
***********************************************************************/
1828
getDetails() {
1929
return `${this.title} has ${this.numberOfPages} pages and was written by ${this.author}`;
2030
}
2131

22-
// returns the total number of pages in the book.
32+
/***********************************************************************
33+
* Returns|int: The total number of pages in the book.
34+
***********************************************************************/
2335
totalPages() {
2436
return this.numberOfPages;
2537
}

0 commit comments

Comments
 (0)