Commit 118be7ac authored by camilo higuita's avatar camilo higuita

booklets basic functionality now ready

parent f9a6c5f7
......@@ -233,7 +233,7 @@ bool DB::update(const QString &tableName, const QVariantMap &updateData, const Q
for (auto key : where.keys())
condition.append(key+" = '"+where[key].toString()+"'");
QString sqlQueryString = "UPDATE " + tableName + " SET " + QString(set.join(",")) + " WHERE " + QString(condition.join(","));
QString sqlQueryString = "UPDATE " + tableName + " SET " + QString(set.join(",")) + " WHERE " + QString(condition.join(" AND "));
auto query = this->getQuery(sqlQueryString);
QVariantList values = updateData.values();
......
......@@ -70,7 +70,26 @@ void Booklet::insert(const QVariantMap &data)
void Booklet::update(const QVariantMap &data, const int &index)
{
qDebug()<< "Trying to udpate a booklet" << data << index;
if(index < 0 || index >= this->m_list.size())
return;
auto newData = this->m_list[index];
QVector<int> roles;
for(const auto &key : data.keys())
if(newData[FMH::MODEL_NAME_KEY[key]] != data[key].toString())
{
newData[FMH::MODEL_NAME_KEY[key]] = data[key].toString();
roles << FMH::MODEL_NAME_KEY[key];
}
this->m_list[index] = newData;
newData[FMH::MODEL_KEY::MODIFIED] = QDateTime::currentDateTime().toString(Qt::TextDate);
this->syncer->updateBooklet(newData[FMH::MODEL_KEY::ID], this->m_book, newData);
emit this->updateModel(index, roles);
}
void Booklet::remove(const int &index)
......
......@@ -123,9 +123,27 @@ void Syncer::insertBook(FMH::MODEL &book)
void Syncer::getBooklet(const QString &id)
{
const auto res = this->db->getDBData(QString("select * from booklets where book = '%1'").arg(id));
const auto res = this->db->getDBData(QString("select * from booklets where book = '%1'").arg(id));
emit this->bookletReady(res);
emit this->bookletReady(res);
}
void Syncer::updateBooklet(const QString &id, const QString &bookId, FMH::MODEL &booklet)
{
if(!this->updateBookletLocal(id, bookId, booklet))
{
qWarning()<< "The booklet could not be updated locally, "
"therefore it was not attempted to update it on the remote server provider, "
"even if it existed.";
return;
}
//to update remote booklet we need to pass the stamp as the id
// const auto stamp = Syncer::noteStampFromId(this->db, id);
// if(!stamp.isEmpty())
// this->updateNoteRemote(stamp, note);
emit this->bookletUpdated(booklet, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Booklet updated locally on the DB"});
}
void Syncer::insertBooklet(const QString &bookId, FMH::MODEL &booklet)
......@@ -376,6 +394,7 @@ void Syncer::updateBookRemote(const QString &id, const FMH::MODEL &book)
bool Syncer::removeBookLocal(const QString &id)
{
return false;
}
......@@ -442,12 +461,31 @@ void Syncer::insertBookletRemote(const QString &bookId, FMH::MODEL &booklet)
}
bool Syncer::updateBookletLocal(const QString &id, const FMH::MODEL &booklet)
bool Syncer::updateBookletLocal(const QString &id, const QString &bookId, const FMH::MODEL &booklet)
{
return false;
// for(const auto &tg : booklet[FMH::MODEL_KEY::TAG])
// 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);
if(__bookletPath.isEmpty())
{
qWarning()<< "File could not be saved. Syncer::insertBookletLocal";
return false;
}
return this->db->update(OWL::TABLEMAP[OWL::TABLE::BOOKLETS],
FMH::toMap(FMH::filterModel(booklet, {FMH::MODEL_KEY::TITLE,
FMH::MODEL_KEY::MODIFIED})),
QVariantMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id},
{FMH::MODEL_NAME[FMH::MODEL_KEY::BOOK], bookId}});
}
void Syncer::updateBookletRemote(const QString &id, const FMH::MODEL &booklet)
void Syncer::updateBookletRemote(const QString &id, const QString &bookId, const FMH::MODEL &booklet)
{
}
......
......@@ -168,7 +168,7 @@ public:
* @param id
* @param booklet
*/
void updateBooklet(const QString &id, FMH::MODEL &booklet);
void updateBooklet(const QString &id, const QString &bookId, FMH::MODEL &booklet);
/**
* @brief insertBooklet
......@@ -256,8 +256,8 @@ protected:
bool insertBookletLocal(const QString &bookId, FMH::MODEL &booklet);
void insertBookletRemote(const QString &bookId, FMH::MODEL &booklet);
bool updateBookletLocal(const QString &id, const FMH::MODEL &booklet);
void updateBookletRemote(const QString &id, const FMH::MODEL &booklet);
bool updateBookletLocal(const QString &id, const QString &bookId, const FMH::MODEL &booklet);
void updateBookletRemote(const QString &id, const QString &bookId, const FMH::MODEL &booklet);
bool removeBookletLocal(const QString &id);
void removeBookletRemote(const QString &id);
......
......@@ -8,9 +8,15 @@ Item
{
id: control
property var currentBooklet : ({})
signal exit()
onCurrentBookletChanged:
{
editor.document.load(currentBooklet.url)
}
Maui.BaseModel
{
id: _bookletModel
......@@ -33,7 +39,12 @@ Item
ToolButton
{
icon.name: "document-save"
// onClicked: control.exit()
onClicked:
{
currentBooklet.content = editor.text
currentBooklet.title = title.text
_booksList.booklet.update(currentBooklet, _listView.currentIndex)
}
},
TextField
......@@ -45,6 +56,7 @@ Item
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
text: currentBooklet.title
// Kirigami.Theme.backgroundColor: selectedColor
// Kirigami.Theme.textColor: Qt.darker(selectedColor, 2.5)
// color: fgColor
......@@ -69,6 +81,7 @@ Item
Maui.Editor
{
id: editor
anchors.fill: parent
visible: !_holder.visible
}
......@@ -144,6 +157,7 @@ Item
{
_listView.currentIndex = index
console.log("Booklet cliked:", _booksList.booklet.get(index).url, _booksList.booklet.get(index).content )
currentBooklet = _booksList.booklet.get(index)
}
}
}
......@@ -168,7 +182,6 @@ Item
anchors.centerIn: parent
icon.name: "list-add"
icon.color: "white"
onClicked: _newChapter.open()
}
}
......
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