Skip to content

Commit

Permalink
Recursive view loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianfrasineanu committed Nov 29, 2016
1 parent 9b4b61e commit 4030d92
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ void Console::loadViews(const fs::path &viewsFolder)
{
this->loadedViews.push_back(it->path().filename());
}

++it;
}
}

void Console::handleView()
{
string content,
path = Console::viewsFolder;
path.append("\\").append(this->currentView.getViewName());
path = findFile(Console::viewsFolder, this->currentView.getViewName()).string();

stringstream buffer;
ifstream viewFile(path, ios::in);
Expand Down
2 changes: 0 additions & 2 deletions app/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

#include <sstream>
#include <stdexcept>
#include <filesystem>

#include "Helpers.h"
#include "View.h"
#include "Controller.h"

using namespace std;
namespace fs = std::experimental::filesystem::v1;

class Console {
private:
Expand Down
17 changes: 17 additions & 0 deletions app/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ void printVector(vector<string> &v)
printw("%s\n", (*it).c_str());
refresh();
}
}

fs::path findFile(const string &directory, const string &fileName)
{
fs::recursive_directory_iterator it(directory);

while (it != fs::recursive_directory_iterator())
{
if (fs::is_regular_file((*it))
&& it->path().filename() == fileName)
{
return it->path();
}
++it;
}

return fs::path(directory);
}
6 changes: 4 additions & 2 deletions app/Helpers.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <Windows.h>
#include <filesystem>

// Please forgive me.
#include <curses.h>

namespace fs = std::experimental::filesystem::v1;
using namespace std;

template<typename V, typename N>
Expand All @@ -32,4 +33,5 @@ void sleepAndFlushInput(unsigned);
void clearScreen();
void getString(string &);
void printString(const char *);
void clearPreviousLines(unsigned);
void clearPreviousLines(unsigned);
fs::path findFile(const string &, const string &);
2 changes: 0 additions & 2 deletions app/ModelInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "Helpers.h"

using namespace std;

//---Model---
//----------------
// The contents of an entity are serialized as a structure with static components.
Expand Down
2 changes: 0 additions & 2 deletions app/RepositoryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "Helpers.h"

using namespace std;

//---Repository---
//----------------
// This entity acts like a glue between the accessor model and the actual model.
Expand Down
2 changes: 1 addition & 1 deletion app/UserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void UserModel::openIOStream()

if (!this->io.is_open())
{
cout << "Couldn't open the file stream path: " << UserModel::pathToFile;
toast(string("Couldn't open the file stream!"), string("error"));
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/UserModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "ModelInterface.h"

using namespace std;

typedef struct {
int id;

Expand Down
2 changes: 2 additions & 0 deletions app/UserRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "RepositoryInterface.h"
#include "UserModel.h"

using namespace std;

class UserRepository : public RepositoryInterface {
private:
static string alias;
Expand Down
2 changes: 2 additions & 0 deletions views/faq.view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Q: At least are there any nice features?

Well, there's some sort of rewarding system similar to the one from StackOverflow. You might like that.

Also, this app is "cursed" literally. You might get what I am saying if you look at the libraries used throughout.

Q: Does it have validation at least?

You bet it has.
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions views/dashboard.view → views/user/dashboard.view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ _\ \ || (_| | (__| </ ___/| | |_| \__ \/ ___/| | |_| \__ \

~~~ Welcome, @output-user-fullname! Make you choice:

-1- Search
-1- Search or ask a question
-2- See your questions
-3- Your profile
-3- Browse a category
-3- Edit your profile
-4- Logout

===========================================================
Expand Down
2 changes: 0 additions & 2 deletions views/login.view → views/user/login.view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ _\ \ || (_| | (__| </ ___/| | |_| \__ \/ ___/| | |_| \__ \
~~~ Holy Molly, you've really created an account didn't you?

Username: @input-user-username

Password: @input-user-password

@action-login

===========================================================
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions views/signup.view → views/user/signup.view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ _\ \ || (_| | (__| </ ___/| | |_| \__ \/ ___/| | |_| \__ \
~~~ Enter your details below:

Full name: @input-user-fullname

Email: @input-user-email

Username: @input-user-username

Password: @input-user-password

@action-signup

===========================================================
Expand Down

0 comments on commit 4030d92

Please sign in to comment.