Skip to content
Snippets Groups Projects
Commit ba761994 authored by Lukáš Paukert's avatar Lukáš Paukert
Browse files

Added basic main webpage in Wt

parent 0a2eb0cf
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ add_subdirectory(lib/SQLiteCpp)
# Source files
set(SOURCES
src/main.cpp
src/ui_wt/MainForm.cpp
src/ui/forms/mainform.cpp
src/ui/widgets/textedit.cpp
src/calculation/InvertedIndex.cpp src/calculation/InvertedIndex.h
......@@ -66,6 +67,8 @@ set(LIBRARIES
Qt5::Widgets
Qt5::Network
SQLiteCpp
wt
wthttp
)
 
# Generate additional sources with MOC and UIC
......
querying/resources/background.png

8.95 KiB

body {
background-image: url("background.png");
font-family: 'Open Sans', sans-serif;
color: #19222a;
text-align: center;
margin: 0;
}
h1 {
margin-bottom: 0;
}
hr {
color: #19222a;
width: 800px;
}
.navigation {
width: 700px;
list-style: none;
padding: 0;
margin: 0 auto;
}
.navigation a {
display: block;
background-color: #D3D3D3;
text-decoration: none;
padding: 10px;
}
.navigation a:hover {
background-color: #A9A9A9;
}
#!/bin/bash
# Exit on first error
set -e
# Create dir build
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
# Build
cmake --build .
# Launch
./Querying --docroot ./../resources --http-address 0.0.0.0 --http-port 3999
#include <iostream>
#include <map>
 
#include <QApplication>
//#include <QApplication>
#include <src/util/ArgumentParser.h>
 
#include "calculation/Query.h"
......@@ -9,15 +9,28 @@
#include "calculation/Computor.h"
#include "util/QueryJSONParser.h"
#include "util/InvertedIndexJSONParser.h"
#include "src/ui/forms/mainform.h"
//#include "src/ui/forms/mainform.h"
#include "src/ui_wt/MainForm.h"
#include "src/database/DocumentCollection.h"
#include "src/database/Document.h"
 
using namespace std;
using namespace cxxopts;
 
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment& env)
{
auto app = Wt::cpp14::make_unique<MainForm>(env);
app->setTitle("Querying: Vector model of information retrieval");
app->useStyleSheet("https://fonts.googleapis.com/css?family=Open+Sans&display=swap");
app->useStyleSheet("style.css");
return std::move(app);
}
int main(int argc, char *argv[]) {
 
return Wt::WRun(argc, argv, &createApplication);
/*
ArgumentParser argumentParser;
switch (argumentParser.parse(argc, argv)) {
case ArgumentParser::HELP: {
......@@ -47,6 +60,7 @@ int main(int argc, char *argv[]) {
mainForm.show();
 
return QApplication::exec();
*/
}
 
/*
......
#include <Wt/WContainerWidget.h>
#include <Wt/WText.h>
#include <Wt/WMenu.h>
#include <Wt/WStackedWidget.h>
#include <fstream>
#include <vector>
#include "./../util/ArgumentParser.h"
#include "./../calculation/Query.h"
#include "./../calculation/Space.h"
#include "./../calculation/Computor.h"
#include "./../util/QueryJSONParser.h"
#include "./../util/InvertedIndexJSONParser.h"
#include "./../database/DocumentCollection.h"
#include "./../database/Document.h"
#include "MainForm.h"
MainForm::MainForm(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
Space space(InvertedIndexJSONParser("./../../data/persistence/invertedList.json").parse());
DocumentCollection collection("./../../data/persistence/docs_and_terms.db");
auto availableDocuments = collection.fetchCollection();
auto container = root()->addWidget(Wt::cpp14::make_unique<Wt::WContainerWidget>());
container->addNew<Wt::WText>("<h1>Choose document to display</h1><hr/>");
auto contents = Wt::cpp14::make_unique<Wt::WStackedWidget>();
Wt::WMenu *menu = container->addNew<Wt::WMenu>(contents.get());
menu->setStyleClass("navigation");
for (int i = 0; i < 10; i++)
{
std::string path = availableDocuments.at(i).name;
menu->addItem(getName(path), Wt::cpp14::make_unique<Wt::WText>(getDocument(path)));
}
container->addWidget(std::move(contents));
}
std::string MainForm::getName(const std::string & path)
{
std::string name = path;
name = name.substr(name.find_last_of('/') + 1);
name = name.substr(0, name.find_last_of('.'));
name.replace(name.find("___"), 3, ": ");
return name;
}
std::string MainForm::getDocument(const std::string & path)
{
std::string content;
std::ifstream file(path);
content.assign((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>() ));
file.close();
encode(content);
size_t start_pos = 0;
while((start_pos = content.find('\n', start_pos)) != std::string::npos) {
content.replace(start_pos, 1, "<br/>");
start_pos += 5;
}
return content;
}
void MainForm::encode(std::string & data) {
std::string buffer;
buffer.reserve(data.size());
for(size_t pos = 0; pos != data.size(); ++pos) {
switch(data[pos]) {
case '&': buffer.append("&amp;"); break;
case '\"': buffer.append("&quot;"); break;
case '\'': buffer.append("&apos;"); break;
case '<': buffer.append("&lt;"); break;
case '>': buffer.append("&gt;"); break;
default: buffer.append(&data[pos], 1); break;
}
}
data.swap(buffer);
}
#pragma once
#include <Wt/WApplication.h>
#include <string>
class MainForm : public Wt::WApplication
{
public:
MainForm(const Wt::WEnvironment& env);
private:
std::string getName(const std::string & path);
std::string getDocument(const std::string & path);
void encode(std::string & content);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment