mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added a new controller for serving the tags in a library
This commit is contained in:
parent
cfffc1bae8
commit
4350d6797e
@ -14,6 +14,7 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "reading_list_item.h"
|
||||
#include "library_item.h"
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
@ -961,6 +962,59 @@ QList<LibraryItem *> DBHelper::getComicsFromParent(qulonglong parentId, QSqlData
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<LabelItem *> DBHelper::getLabelItems(qulonglong libraryId)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||
|
||||
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db); //TODO add some kind of
|
||||
QList<LabelItem *> labels;
|
||||
|
||||
while(selectQuery.next())
|
||||
{
|
||||
QSqlRecord record = selectQuery.record();
|
||||
LabelItem *item = new LabelItem(QList<QVariant>()
|
||||
<< record.value("name")
|
||||
<< record.value("color")
|
||||
<< record.value("id")
|
||||
<< record.value("ordering"));
|
||||
|
||||
if(labels.isEmpty())
|
||||
{
|
||||
labels << item;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (i < labels.count() && (labels.at(i)->colorid() < item->colorid()) )
|
||||
i++;
|
||||
|
||||
if(i < labels.count())
|
||||
{
|
||||
if(labels.at(i)->colorid() == item->colorid()) //sort by name
|
||||
{
|
||||
while( i < labels.count() && labels.at(i)->colorid() == item->colorid() && naturalSortLessThanCI(labels.at(i)->name(),item->name()))
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if(i >= labels.count())
|
||||
{
|
||||
labels << item;
|
||||
}
|
||||
else
|
||||
{
|
||||
labels.insert(i,item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
||||
//loads
|
||||
Folder DBHelper::loadFolder(qulonglong id, QSqlDatabase & db)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ class QString;
|
||||
class ComicDB;
|
||||
class Folder;
|
||||
class LibraryItem;
|
||||
class LabelItem;
|
||||
class QSqlDatabase;
|
||||
class ComicInfo;
|
||||
class QSqlRecord;
|
||||
@ -73,6 +74,7 @@ public:
|
||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
static QList<ComicDB> getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db);
|
||||
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||
static QList<LabelItem *> getLabelItems(qulonglong libraryId);
|
||||
//load
|
||||
static Folder loadFolder(qulonglong id, QSqlDatabase & db);
|
||||
static Folder loadFolder(const QString & folderName, qulonglong parentId, QSqlDatabase & db);
|
||||
|
30
YACReaderLibrary/server/controllers/tagscontroller.cpp
Normal file
30
YACReaderLibrary/server/controllers/tagscontroller.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "tagscontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "reading_list_item.h"
|
||||
#include "../static.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
TagsController::TagsController() {}
|
||||
|
||||
void TagsController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(2).toInt();
|
||||
|
||||
QList<LabelItem *> tags = DBHelper::getLabelItems(libraryId);
|
||||
|
||||
foreach(LabelItem * tag, tags)
|
||||
{
|
||||
response.writeText(QString("%1\t%2\t%3\r\n").arg(tag->getId()).arg(tag->name()).arg(labelColorToRGBString(tag->colorid())));
|
||||
}
|
||||
|
||||
response.writeText("",true);
|
||||
}
|
22
YACReaderLibrary/server/controllers/tagscontroller.h
Normal file
22
YACReaderLibrary/server/controllers/tagscontroller.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef TAGSCONTROLLER_H
|
||||
#define TAGSCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
|
||||
|
||||
class TagsController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TagsController)
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
TagsController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // TAGSCONTROLLER_H
|
@ -24,6 +24,7 @@
|
||||
#include "controllers/synccontroller.h"
|
||||
#include "controllers/versioncontroller.h"
|
||||
#include "controllers/foldercontentcontroller.h"
|
||||
#include "controllers/tagscontroller.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
@ -109,6 +110,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
QRegExp comicPageRemote("/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); //get comic page (remote reading)
|
||||
QRegExp serverVersion("/version/?");
|
||||
QRegExp folderContent("/library/.+/folder/[0-9]+/content/?");
|
||||
QRegExp tags("/library/.+/tags/?");
|
||||
|
||||
QRegExp sync("/sync");
|
||||
|
||||
@ -175,6 +177,10 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
{
|
||||
FolderContentController().service(request, response);
|
||||
}
|
||||
else if(tags.exactMatch(path))
|
||||
{
|
||||
TagsController().service(request, response);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -18,7 +18,8 @@ HEADERS += \
|
||||
$$PWD/controllers/synccontroller.h \
|
||||
#v2
|
||||
$$PWD/controllers/versioncontroller.h \
|
||||
$$PWD/controllers/foldercontentcontroller.h
|
||||
$$PWD/controllers/foldercontentcontroller.h \
|
||||
$$PWD/controllers/tagscontroller.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/static.cpp \
|
||||
@ -37,7 +38,8 @@ SOURCES += \
|
||||
$$PWD/controllers/synccontroller.cpp \
|
||||
#v2
|
||||
$$PWD/controllers/versioncontroller.cpp \
|
||||
$$PWD/controllers/foldercontentcontroller.cpp
|
||||
$$PWD/controllers/foldercontentcontroller.cpp \
|
||||
$$PWD/controllers/tagscontroller.cpp
|
||||
|
||||
include(lib/bfLogging/bfLogging.pri)
|
||||
include(lib/bfHttpServer/bfHttpServer.pri)
|
||||
|
Loading…
x
Reference in New Issue
Block a user