Commit df336942 authored by camilo higuita's avatar camilo higuita

now booklets are correctly updated from server on startup and booklets get...

now booklets are correctly updated from server on startup and booklets get auto selected to the last booklet
parent 0dca2ce9
......@@ -45,6 +45,8 @@ SOURCES += \
src/syncing/syncer.cpp \
src/utils/htmlparser.cpp \
src/models/notes/notes.cpp \
src/models/books/books.cpp \
src/models/books/booklet.cpp \
src/models/links/links.cpp \
src/providers/nextnote.cpp \
......@@ -60,6 +62,8 @@ HEADERS += \
src/linker.h \
src/utils/htmlparser.h \
src/models/notes/notes.h \
src/models/books/books.h \
src/models/books/booklet.h \
src/models/links/links.h \
src/providers/nextnote.h \
src/providers/abstractnotesprovider.h
......
......@@ -31,6 +31,7 @@ id TEXT,
book TEXT,
url TEXT,
title TEXT NOT NULL,
favorite INT,
adddate DATE,
modified DATE,
PRIMARY KEY(id, book),
......
......@@ -276,6 +276,8 @@ void Syncer::setConections()
FMH::MODEL_KEY::STAMP,
FMH::MODEL_KEY::USER,
FMH::MODEL_KEY::SERVER})));
emit this->noteInserted(__note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note inserted on local db, from the server provider"});
}else
{
......@@ -286,7 +288,7 @@ void Syncer::setConections()
FMH::MODEL_KEY::FAVORITE});
__note[FMH::MODEL_KEY::MODIFIED] = QDateTime::fromSecsSinceEpoch(note[FMH::MODEL_KEY::MODIFIED].toInt()).toString(Qt::TextDate);
this->updateNoteLocal(id, __note);
emit this->noteInserted(note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note inserted on local db, from the server provider"});
emit this->noteUpdated(__note, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note updated on local db, from the server provider"});
}
}
......@@ -336,6 +338,7 @@ void Syncer::setConections()
FMH::MODEL_KEY::STAMP,
FMH::MODEL_KEY::USER,
FMH::MODEL_KEY::SERVER})));
emit this->bookletInserted(__booklet, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Booklet inserted on local db, from the server provider"});
}else
{
......@@ -344,9 +347,17 @@ void Syncer::setConections()
FMH::MODEL_KEY::CONTENT,
FMH::MODEL_KEY::MODIFIED,
FMH::MODEL_KEY::FAVORITE});
__booklet[FMH::MODEL_KEY::ID] = id;
__booklet[FMH::MODEL_KEY::BOOK] = booklet[FMH::MODEL_KEY::CATEGORY];
__booklet[FMH::MODEL_KEY::URL] = [&]()-> QString {
const auto data = this->db->getDBData(QString("select url from booklets where id = '%1'").arg(id));
return data.isEmpty() ? QString() : data.first()[FMH::MODEL_KEY::URL]; }();
qDebug()<< " trying to update local booklets with url" << __booklet[FMH::MODEL_KEY::URL] << __booklet[FMH::MODEL_KEY::BOOK] << __booklet[FMH::MODEL_KEY::CONTENT] ;
__booklet[FMH::MODEL_KEY::MODIFIED] = QDateTime::fromSecsSinceEpoch(booklet[FMH::MODEL_KEY::MODIFIED].toInt()).toString(Qt::TextDate);
this->updateNoteLocal(id, __booklet);
emit this->noteInserted(booklet, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Note inserted on local db, from the server provider"});
this->updateBookletLocal(id, __booklet[FMH::MODEL_KEY::BOOK], __booklet);
emit this->bookletUpdated(__booklet, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Booklet updated on local db, from the server provider"});
}
}
......@@ -365,7 +376,15 @@ void Syncer::setConections()
{
const auto id = Syncer::bookletIdFromStamp(this->db, this->provider->provider(), booklet[FMH::MODEL_KEY::ID]);
if(!booklet.isEmpty())
this->updateBookletLocal(id, booklet[FMH::MODEL_KEY::CATEGORY], FMH::filterModel(booklet, {FMH::MODEL_KEY::TITLE}));
{
booklet[FMH::MODEL_KEY::ID] = id;
booklet[FMH::MODEL_KEY::BOOK] = booklet[FMH::MODEL_KEY::CATEGORY];
booklet[FMH::MODEL_KEY::URL] = [&]()-> QString {
const auto data = this->db->getDBData(QString("select url from booklets where id = '%1'").arg(id));
return data.isEmpty() ? QString() : data.first()[FMH::MODEL_KEY::URL]; }();
this->updateBookletLocal(id, booklet[FMH::MODEL_KEY::BOOK], FMH::filterModel(booklet, {FMH::MODEL_KEY::TITLE}));
}
emit this->bookletUpdated(booklet, {STATE::TYPE::REMOTE, STATE::STATUS::OK, "Booklet updated on server provider"});
});
......@@ -574,8 +593,8 @@ bool Syncer::updateBookletLocal(const QString &id, const QString &bookId, const
// this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::NOTES], id);
const QUrl __path = QFileInfo(booklet[FMH::MODEL_KEY::URL]).dir().path();
qDebug()<< "Updating local txt file as"<< __path.toLocalFile();
const auto __bookletPath = Syncer::saveNoteFile(__path.toLocalFile()+"/", booklet);
qDebug()<< "Updating local txt file as"<< __path.toLocalFile() << __bookletPath;
if(__bookletPath.isEmpty())
{
......@@ -585,7 +604,8 @@ bool Syncer::updateBookletLocal(const QString &id, const QString &bookId, const
return this->db->update(OWL::TABLEMAP[OWL::TABLE::BOOKLETS],
FMH::toMap(FMH::filterModel(booklet, {FMH::MODEL_KEY::TITLE,
FMH::MODEL_KEY::MODIFIED})),
FMH::MODEL_KEY::MODIFIED,
FMH::MODEL_KEY::FAVORITE})),
QVariantMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id},
{FMH::MODEL_NAME[FMH::MODEL_KEY::BOOK], bookId}});
......
......@@ -8,7 +8,7 @@ Item
{
id: control
property var currentBooklet : ({})
property var currentBooklet : null
signal exit()
......@@ -16,8 +16,7 @@ Item
{
editor.document.load(currentBooklet.url)
_drawerPage.title = currentBook.title
}
}
Maui.BaseModel
{
......@@ -74,7 +73,7 @@ Item
Maui.Holder
{
id: _holder
visible: !_listView.count
visible: !_listView.count || !currentBooklet
emoji: "qrc:/Type.png"
emojiSize: iconSizes.huge
isMask: false
......@@ -151,6 +150,13 @@ Item
anchors.fill: parent
model: _bookletModel
clip: true
onCountChanged:
{
_listView.currentIndex = count-1
control.currentBooklet = _booksList.booklet.get(_listView.currentIndex)
}
delegate: Maui.LabelDelegate
{
id: _delegate
......@@ -163,13 +169,10 @@ Item
onClicked:
{
_listView.currentIndex = index
console.log("Booklet cliked:", _booksList.booklet.get(index).url, _booksList.booklet.get(index).content )
currentBooklet = _booksList.booklet.get(index)
}
}
}
}
Rectangle
......@@ -193,9 +196,6 @@ Item
}
}
}
}
}
}
......@@ -13,7 +13,7 @@ Maui.Dialog
maxWidth: 700*unit
maxHeight: maxWidth
property string selectedColor : "#ffffe6"
property string selectedColor : Kirigami.Theme.backgroundColor
property string fgColor: Qt.darker(selectedColor, 3)
property bool showEditActions : false
......@@ -148,7 +148,7 @@ Maui.Dialog
{
title.text = note.title
editor.body.text = note.content
selectedColor = note.color ? note.color : Kirigami.Theme.backgroundColor
control.selectedColor = note.color ? note.color : Kirigami.Theme.backgroundColor
pinButton.checked = note.pin == 1
favButton.checked = note.favorite == 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment