Display used storage space in UI

This commit is contained in:
Tina_Azure
2023-08-02 18:16:22 +02:00
parent f2bbadcf70
commit 008b6edce1
5 changed files with 24 additions and 5 deletions

View File

@ -671,6 +671,18 @@ namespace Database {
work.commit();
}
/*
* Executes the prepared statement SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE
* Takes an open pqxx::connection and the freelancer email
* returns the sum of MB of all submissions in the database if none exist 0 is returned
*/
pqxx::result executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE(pqxx::connection &connection, const std::string& freelancerEmail) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE, freelancerEmail);
work.commit();
return result;
}
/*
* Prepares a statement based on ID
* Takes an open pqxx::connection, the statement id

View File

@ -246,7 +246,7 @@ namespace DatabaseStatementConstCollection {
* Name and Statement for prepared statement to select MB of used freelancer storage
*/
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE = "selectFreelancerFileSubmissionUsedStorage";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE = "select round(sum(filesize) / 1024.0 / 1024.0, 4) from freelancersubmissions where freelancerid = (select freelancers.id from freelancers where emailaddress = $1)";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE = "select round(coalesce(sum(filesize), 0) / 1024.0 / 1024.0, 4) from freelancersubmissions where freelancerid = (select freelancers.id from freelancers where emailaddress = $1)";
/*
* Name and Statement for prepared statement to select fullpath of a submission based on freelancer email and filename

View File

@ -983,9 +983,16 @@ int main(int argc, char *argv[]) {
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
size_t usedStorageInMB = 0; //todo:database operation
pqxx::connection databaseConnection(configuration.databaseConnectionString);
Database::prepareStatements(databaseConnection, {
ID_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE
});
pqxx::result freelancerUsedStorageResult = Database::executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_USED_STORAGE(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
double usedStorageInMB = stod(freelancerUsedStorageResult.at(0).at(0).c_str());
size_t maxStorageInMB = configuration.submissionMaxtotalStorageMB;
ctx[MUSTACHE_FREELANCER_AVAILIBLE_STORAGE_IN_MB] = usedStorageInMB;
ctx[MUSTACHE_FREELANCER_USED_STORAGE_IN_MB] = usedStorageInMB;
ctx[MUSTACHE_FREELANCER_MAXIMUM_STORAGE_IN_MB] = maxStorageInMB;
ctx[MUSTACHE_FREELANCER_MAXIMUM_FILE_NAME_SIZE] = configuration.submissionMaxFileNameSize;

View File

@ -87,7 +87,7 @@ namespace TemplateConstCollection {
const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT = "OPERATION_EDIT";
const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE = "OPERATION_DELETE";
const static std::string MUSTACHE_FREELANCER_SUBMISSION_NAME = "FILE_SUBMISSION";
const static std::string MUSTACHE_FREELANCER_AVAILIBLE_STORAGE_IN_MB = "AVAILIBLE_STORAGE_IN_MB";
const static std::string MUSTACHE_FREELANCER_USED_STORAGE_IN_MB = "USED_STORAGE_IN_MB";
const static std::string MUSTACHE_FREELANCER_MAXIMUM_STORAGE_IN_MB = "MAXIMUM_STORAGE_IN_MB";
const static std::string MUSTACHE_FREELANCER_MAXIMUM_FILE_NAME_SIZE = "MAXIMUM_FILE_NAME_SIZE";
const static std::string MUSTACHE_FREELANCER_ALLOWED_FILE_TYPES_LIST_COMMA_SEPARATED = "ALLOWED_FILE_TYPES_LIST_COMMA_SEPARATED";

View File

@ -11,7 +11,7 @@
{{#COOKIE_LOGGED_IN}}
<div>
<p>
Availible Space: {{AVAILIBLE_STORAGE_IN_MB}} MB / {{MAXIMUM_STORAGE_IN_MB}} MB
Used Storage Space: {{USED_STORAGE_IN_MB}} MB / {{MAXIMUM_STORAGE_IN_MB}} MB
</p>
<p>
Allowed File Types: {{ALLOWED_FILE_TYPES_LIST_COMMA_SEPARATED}}