Skip to content

Commit

Permalink
app changes
Browse files Browse the repository at this point in the history
  • Loading branch information
a3st committed Jun 3, 2024
1 parent 63b66b7 commit 4371bbd
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 67 deletions.
5 changes: 3 additions & 2 deletions include/note_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ namespace notes

void saveNoteToDB(Note const& note);

void removeNoteFromDB(uint32_t const ID);

private:
SQLite::Database database;
std::vector<Note> notes;

void loadNotesFromDB();
std::vector<Note> loadNotesFromDB() const;
bool tryCreateNotesDB();
};
} // namespace notes
2 changes: 2 additions & 0 deletions include/view_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace notes

void saveNote(uint32_t ID, std::string noteName, std::string noteData);

void removeNote(uint32_t ID);

private:
libwebview::App* app;
NoteStorage noteStorage;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ int32_t main(int32_t argc, char** argv)
try
{
libwebview::App app("notes-app", "Notes", 580, 600, true, true);
app.setMinWindowSize(580, 600);

notes::ViewModel viewModel(&app);

Expand Down
38 changes: 21 additions & 17 deletions src/note_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ namespace notes
{
throw std::runtime_error("An error occurred when adding a new table to the database");
}

this->loadNotesFromDB();
}

void NoteStorage::loadNotesFromDB()
std::vector<Note> NoteStorage::loadNotesFromDB() const
{
notes.clear();
std::vector<Note> notes;

std::string const dbSelectSQL("SELECT `id` ,`name`, `data` FROM `notes`");

Expand All @@ -28,6 +26,7 @@ namespace notes

notes.emplace_back(noteID, noteName, noteData);
}
return notes;
}

bool NoteStorage::tryCreateNotesDB()
Expand Down Expand Up @@ -66,38 +65,43 @@ namespace notes
std::string const dbAddNoteSQL = std::format(
"INSERT INTO `notes` (`name`, `data`) VALUES ('{}', '{}') RETURNING id", note.noteName, note.noteData);

uint32_t const noteID = database.execAndGet(dbAddNoteSQL).getInt();

notes.emplace_back(noteID, note.noteName, note.noteData);
int32_t const result = database.tryExec(dbAddNoteSQL);
if (result != SQLite::OK)
{
throw std::runtime_error("An error occurred when adding a row to the database");
}
}
else
{
std::string const dbUpdateNoteSQL = std::format("UPDATE `notes` SET `name`='{}', `data`='{}' WHERE `id`={}",
note.noteName, note.noteData, note.noteID);

int32_t result = database.tryExec(dbUpdateNoteSQL);
int32_t const result = database.tryExec(dbUpdateNoteSQL);
if (result != SQLite::OK)
{
throw std::runtime_error("An error occurred when updating a row to the database");
}
}
}

auto found = std::find_if(notes.begin(), notes.end(),
[&](auto const& element) { return note.noteID == element.noteID; });
if (found != notes.end())
{
found->noteName = note.noteName;
found->noteData = note.noteData;
}
void NoteStorage::removeNoteFromDB(uint32_t const ID)
{
std::string const dbDeleteSQL = std::format("DELETE FROM `notes` WHERE `id`={}", ID);

int32_t const result = database.tryExec(dbDeleteSQL);
if (result != SQLite::OK)
{
throw std::runtime_error("An error occurred when updating a row to the database");
}
}

std::string NoteStorage::getNotesData() const
{
std::stringstream stream;

stream << "{\"notes\":[";

bool isFirst = true;
for (auto const& note : notes)
for (auto const& note : this->loadNotesFromDB())
{
if (!isFirst)
{
Expand Down
6 changes: 6 additions & 0 deletions src/view_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace notes
app->bind("saveNote", [this](uint32_t ID, std::string noteName, std::string noteData) -> void {
saveNote(ID, noteName, noteData);
});
app->bind("removeNote", [this](uint32_t ID) -> void { removeNote(ID); });
}

std::string ViewModel::getNotes()
Expand All @@ -20,4 +21,9 @@ namespace notes
{
noteStorage.saveNoteToDB(Note(ID, noteName, noteData));
}

void ViewModel::removeNote(uint32_t ID)
{
noteStorage.removeNoteFromDB(ID);
}
} // namespace notes
27 changes: 19 additions & 8 deletions ui/dist/app.bundle.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"babel-loader": "^9.1.3",
"css-loader": "^7.1.2",
"ctxmenu": "^1.7.0",
"filemanager-webpack-plugin": "^8.0.0",
"jquery": "^3.7.1",
"marked": "^12.0.2",
Expand Down
32 changes: 13 additions & 19 deletions ui/src/components/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,12 @@
<object style="pointer-events: none;" data="images/eye.svg" width="20" height="20"></object>
</button>

<button title="Экспорт" class="btn-icon circle" style="width: 36px; height: 36px;" @click="onExportClick($event)">
<button id="export-btn" title="Экспорт" class="btn-icon circle" style="width: 36px; height: 36px;" @click="onExportClick($event)">
<object style="pointer-events: none;" data="images/file-export.svg" width="20" height="20"></object>
</button>

<div v-if="isOpenExport" class="expand-inline-menu" style="background-color: rgb(245, 245, 220);">
<button title="PDF" class="btn-icon circle" style="width: 36px; height: 36px;" @click="">
<object style="pointer-events: none;" data="images/pdf.svg" width="20" height="20"></object>
</button>

<button title="DOCX" class="btn-icon circle" style="width: 36px; height: 36px;" @click="">
<object style="pointer-events: none;" data="images/doc.svg" width="20" height="20"></object>
</button>

<button title="TXT" class="btn-icon circle" style="width: 36px; height: 36px;" @click="">
<object style="pointer-events: none;" data="images/txt.svg" width="20" height="20"></object>
</button>
</div>
</div>
<div style="display: flex; flex-direction: row; margin-left: auto;">
<button class="btn-text" @click="onSaveClick($event)" style="font-weight: bold;">Сохранить</button>
<button v-show="this.title.length > 0" class="btn-text" @click="onSaveClick($event)" style="font-weight: bold;">Сохранить</button>
<button class="btn-text" @click="onCloseClick($event)" style="font-weight: bold;">Закрыть</button>
</div>
</div>
Expand All @@ -49,14 +35,14 @@

<script>
import { marked } from 'marked';
import { ctxmenu } from 'ctxmenu';
import $ from 'jquery';
export default {
emits: ['save'],
data() {
return {
isOpenEditor: false,
isOpenExport: false,
isPreview: false,
content: "",
title: "",
Expand All @@ -67,6 +53,9 @@ export default {
previewText() {
return marked(this.content);
}
},
mounted() {
},
methods: {
onFocusInput(e) {
Expand All @@ -81,7 +70,6 @@ export default {
this.title = "";
this.content = "";
this.isOpenEditor = false;
this.isOpenExport = false;
this.isPreview = false;
this.id = -1;
},
Expand All @@ -90,7 +78,13 @@ export default {
this.onCloseClick();
},
onExportClick(e) {
this.isOpenExport = !this.isOpenExport;
e.stopPropagation();
ctxmenu.show([
{ text: "Экспорт" },
{ text: ".TXT", action: () => alert("Hello World!") },
{ text: ".PDF", action: () => alert("Hello World!") },
{ text: ".DOCX", action: () => alert("Hello World!") },
], e.target);
},
open(preview) {
this.isOpenEditor = true;
Expand Down
85 changes: 70 additions & 15 deletions ui/src/components/note.vue
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
<template>
<div class="note-container" @mousedown="$emit('click', $event)">
<div class="note-container">
<div class="note-header-container">
<span class="note-title">{{ title }}</span>
<span class="note-title" @mousedown="$emit('click', $event)">{{ title }}</span>

<div style="display: flex; flex-direction: row; margin-left: auto;">
<div v-if="isOpenExt" class="expand-inline-menu" style="background-color: rgb(227, 221, 192);">
<button title="Удалить" class="btn-icon circle" style="width: 22px; height: 22px;" @click="">
<object style="pointer-events: none;" data="images/trash.svg" width="10" height="10"></object>
</button>
</div>
<button class="btn-icon" @click="onOpenExtClick($event)">
<button class="btn-icon" @click="onContextClick($event)">
<object style="pointer-events: none;" data="images/ellipsis.svg" width="16" height="16"></object>
</button>
</div>
</div>

<div class="note-body-container">1</div>
<div class="note-body-container" v-html="description" @mousedown="$emit('click', $event)"></div>
</div>
</template>

<script>
import {marked} from 'marked'
export default {
emits: ['click'],
emits: ['click', 'context'],
props: {
title: String,
data: String
},
data() {
return {
isOpenExt: false
computed: {
description() {
return marked(this.data);
}
},
methods: {
onOpenExtClick(e) {
this.isOpenExt = !this.isOpenExt;
onContextClick(e) {
this.$emit('context', e);
}
}
}
Expand Down Expand Up @@ -83,6 +80,64 @@ export default {
.note-body-container {
display: flex;
flex-direction: column;
padding: 5px;
margin: 5px;
overflow: hidden;
}
.note-body-container h1 {
font-size: 16px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container h2 {
font-size: 14px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container h3 {
font-size: 12px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container h4 {
font-size: 10px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container h5 {
font-size: 8px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container h6 {
font-size: 6px;
margin: 2px 0px 0px 0px;
font-weight: normal;
}
.note-body-container p {
font-size: 12px;
margin: 1px 0px 0px 0px;
font-weight: normal;
}
.note-body-container ol, ul {
margin: 1px 0px 0px 0px;
}
.note-body-container li {
font-size: 10px;
}
.note-body-container img {
width: 50%;
height: auto;
}
</style>
Loading

0 comments on commit 4371bbd

Please sign in to comment.