Skip to content

Commit 1af11a0

Browse files
committed
added table switcher demo version
created notes' table builder icon code updated so they are in same style added call of refreshing tables function to load local data into the tables
1 parent 3dd4b6d commit 1af11a0

File tree

6 files changed

+192
-29
lines changed

6 files changed

+192
-29
lines changed

index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1>Hometask #1 | JavaScript</h1>
2323
<th class="content">Content</th>
2424
<th class="dates">Dates</th>
2525
<th class="header-icon">&nbsp;</th>
26-
<th class="header-icon archive" onclick="switchTables()"></th>
26+
<th class="header-icon archive" id="table-switcher"></th>
2727
<th class="header-icon delete"></th>
2828
</tr>
2929
</thead>
@@ -32,8 +32,6 @@ <h1>Hometask #1 | JavaScript</h1>
3232

3333

3434
<div id="create-note">
35-
<button id="build-stats">build-stats</button>
36-
<button >Load local data</button>
3735
<button id="create-note-button">Create Note</button>
3836
</div>
3937

mainThread.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
loadIconsIntoHeader,
3-
notes
4-
} from './scripts/HTMLBuilder.js';
5-
6-
loadIconsIntoHeader( );
1+
import { loadIconsIntoHeader, refreshTables } from './scripts/HTMLBuilder.js';
72

3+
loadIconsIntoHeader();
4+
refreshTables();

scripts/HTMLBuilder.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { notes, categories, icons } from './data.js';
2-
import { makeID, getDatesFromText } from "./functions.js";
3-
// import { makeID } from "./functions";
2+
import { makeRandomID, getDatesFromText } from "./functions.js";
3+
44

55
let statisticsTable = document.getElementById('stats-table'),
66
notesTable = document.getElementById('active-archive-table');
77

8+
let activeNoteTableShown = true;
9+
810

911
function loadIconsIntoHeader(){
1012
Array.from(document.getElementsByClassName('header-icon')).forEach(col => {
@@ -31,16 +33,19 @@ function buildForm(name, created, category, content){
3133

3234
form.onsubmit = (event)=>{
3335
event.preventDefault();
34-
35-
createNote({
36-
id: makeID(10),
36+
let note = {
37+
id: makeRandomID(10),
3738
name: event.target.name.value,
3839
created: new Date(),
3940
category: event.target.categories.value,
4041
content: event.target.content.value,
4142
dates: getDatesFromText(event.target.content.value),
4243
archived: false
43-
});
44+
}
45+
46+
createNote(note);
47+
48+
document.getElementsByClassName('wrapper-div')[0].remove();
4449
};
4550

4651

@@ -68,11 +73,11 @@ function deleteNote(noteID){
6873

6974
function refreshTables(){
7075
clearAllTables();
76+
buildNotesTable();
7177
buildStatisticTable();
72-
// buildNotesTable();
7378
}
7479
function clearAllTables(){
75-
// clearInnerHTML(notesTable);
80+
clearInnerHTML(notesTable);
7681
clearInnerHTML(statisticsTable);
7782
}
7883
function clearInnerHTML(parent){
@@ -123,15 +128,41 @@ function buildStatTr(category, active, total){
123128
}
124129

125130
function buildNotesTable(){
131+
notes.forEach(note => {
132+
if (!note.archived === activeNoteTableShown)
133+
notesTable.innerHTML += buildNotesTr(note);
134+
})
126135

127136
}
137+
function buildNotesTr(note){
138+
return `
139+
<tr>
140+
<td className="category-icon">${ categories[note.category] }</td>
141+
<td className="name">${ note.name }</td>
142+
<td className="created">${ note.created.toLocaleDateString() }</td>
143+
<td className="category1">${ note.category }</td>
144+
<td className="content">${ note.content }</td>
145+
<td className="dates">${ note.dates }</td>
146+
<td className="row-icon edit"></td>
147+
<td className="row-icon archive"></td>
148+
<td className="row-icon delete"></td>
149+
</tr>
150+
`;
151+
}
128152

129153
export {
130154
refreshTables,
131155
loadIconsIntoHeader,
132156
notes
133157
}
134158

159+
function switchTables() {
160+
activeNoteTableShown = !activeNoteTableShown;
161+
clearInnerHTML(notesTable);
162+
buildNotesTable();
163+
document.getElementsByClassName('header-icon archive')[0].innerHTML = (activeNoteTableShown)? icons.ARCHIVE_ICON : icons.UNARCHIVE_ICON;
164+
}
135165

166+
document.getElementById("table-switcher").addEventListener("click", switchTables);
136167
document.getElementById("create-note-button").addEventListener("click", buildForm);
137-
document.getElementById("build-stats").addEventListener("click", refreshTables);
168+
// document.getElementById("build-stats").addEventListener("click", refreshTables);

scripts/data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export let notes = [
5353
category: "Quote",
5454
content: "Power doesn't come with bla bla bla",
5555
dates: "",
56-
archived: false
56+
archived: true
5757
},
5858
{
5959
id: "LI_RUnkMNo",
@@ -62,7 +62,7 @@ export let notes = [
6262
category: "Task",
6363
content: "The Lean Statrup",
6464
dates: "",
65-
archived: false
65+
archived: true
6666
},
6767
// {
6868
// name: "",

scripts/functions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function makeID (length) {
1+
export function makeRandomID (length) {
22
let result = '',
33
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
44

@@ -7,6 +7,7 @@ export function makeID (length) {
77

88
return result;
99
}
10+
1011
export function getDatesFromText(text){
1112
let results = text.match(/[0-9]{1,2}([\-\/ \.])[0-9]{1,2}([\-\/ \.])((19)|(20))[0-9]{2}/g);
1213

0 commit comments

Comments
 (0)