diff --git a/DapHalper.h b/DapHalper.h index 1c96e87cc445f94b45401d0ff70596c3b6c4940b..fea5511054c957b28891271f9ae4884dc728b0df 100644 --- a/DapHalper.h +++ b/DapHalper.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the libCellFrameDashboardClient library. +** This file is part of the libdap-qt-ui-chain-wallet library. ** ** The class provides common functionality. ** diff --git a/DapSettings.h b/DapSettings.h index 7469a253f90d9bc2c57eeb717f468e0db05b8e2c..dc52b3d9fdc5d351796fb38ba0ca97f2d385d15d 100644 --- a/DapSettings.h +++ b/DapSettings.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the CellFrameDashboardGUI application. +** This file is part of the libdap-qt-ui-chain-wallet application. ** ** The class provides an interface for managing application settings. ** Record format - Json. diff --git a/handlers/DapAbstractCommand.h b/handlers/DapAbstractCommand.h index f2fe31f3c85d341f8f3246b6e902c67c7c709b65..70b2d9825095e430483ddaf5f0e8e4220b648777 100644 --- a/handlers/DapAbstractCommand.h +++ b/handlers/DapAbstractCommand.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the libCellFrameDashboardClient library. +** This file is part of the libdap-qt-ui-chain-wallet library. ** ** The class implements the command interface. ** diff --git a/handlers/DapActivateClientCommand.h b/handlers/DapActivateClientCommand.h index 9ff28743d158c43e37c6dd299406b6b7b6f46343..05e8f1c4ea8dbee484c77fe923488404eb4d5e5e 100644 --- a/handlers/DapActivateClientCommand.h +++ b/handlers/DapActivateClientCommand.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the libCellFrameDashboardClient library. +** This file is part of the libdap-qt-ui-chain-wallet library. ** ** The class implements the command to activate the GUI client. That is, ** by clicking on the icon in the system tray, the main window of the GUI diff --git a/handlers/DapAddWalletCommand.h b/handlers/DapAddWalletCommand.h index ea649f5d6e4d8aad1301583cf88a175b715305c5..f76cc0d6e6cbe0ef46b46b4655bebdbb109828d7 100644 --- a/handlers/DapAddWalletCommand.h +++ b/handlers/DapAddWalletCommand.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the libCellFrameDashboardClient library. +** This file is part of the libdap-qt-ui-chain-wallet library. ** ** The class implements the functionality of creating a new wallet. ** diff --git a/handlers/DapGetListWalletsCommand.cpp b/handlers/DapGetListWalletsCommand.cpp index 82c11e9606ac1e8ebc157d18353c749512c445b8..9da645d18b82d290d9892c405c364395a8d33026 100644 --- a/handlers/DapGetListWalletsCommand.cpp +++ b/handlers/DapGetListWalletsCommand.cpp @@ -31,84 +31,7 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q Q_UNUSED(arg9) Q_UNUSED(arg10) -// DapWallet wallet; -// wallet.setName("VASY"); -// wallet.setBalance(25.5); -// wallet.setIcon("/fsghdhjghjufkigl"); -// wallet.addNetwork("Kelvin-testnet"); -// wallet.addNetwork("Private"); -// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); -// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); - -// DapWalletToken token1("KLV", &wallet); -// token1.setBalance(5.5); -// token1.setNetwork("Kelvin-testnet"); -// token1.setEmission(464645646546); -// DapWalletToken token2("CELL", &wallet); -// token2.setBalance(100); -// token2.setNetwork("Private"); -// token2.setEmission(121212121); -// wallet.addToken(&token1); -// wallet.addToken(&token2); - -// QByteArray datas; -// QDataStream out(&datas, QIODevice::WriteOnly); -// out << wallet; - -// qDebug() << "balance after:\t" << wallet.getBalance(); -// qDebug() << "icon after:\t" << wallet.getIcon(); -// qDebug() << "networks after:\t" << wallet.getNetworks(); -// qDebug() << "m_aAddresses after:\t" << wallet.getAddresses(); -// qDebug() << "m_aTokens after:\t" << wallet.getTokens(); - - -// DapWallet wallet2; -// QByteArray d (datas); -// QDataStream in(&d, QIODevice::ReadOnly); -// in >> wallet2; - -// qDebug() << endl; -// qDebug() << "name before:\t" << wallet2.getName(); -// qDebug() << "balance before:\t" << wallet2.getBalance(); -// qDebug() << "icon before:\t" << wallet2.getIcon(); -// qDebug() << "networks before:\t" << wallet2.getNetworks(); -// qDebug() << "m_aAddresses before:\t" << wallet2.getAddresses(); -// // qDebug() << "m_aTokens before:\t" << wallet2.m_aTokens; - -// foreach (auto w, wallet2.getTokens()) { -// qDebug() << static_cast<DapWalletToken*>(w)->getName() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getBalance() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getEmission() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getNetwork() << endl; - -// } - - -// QJsonValue str = QJsonValue::fromVariant(datas.toHex()); - - - -// QByteArray b = QByteArray::fromHex(str.toVariant().toByteArray()); -// std::string s = datas.toStdString(); -// QString str = QString::fromStdString(s); - -// DapWallet w; -// QByteArray d; -// QDataStream in(&datas, QIODevice::ReadOnly); -// in>>w; - - QList<DapWallet> wallets; - - QStringList list; - QProcess processN; - processN.start(QString("%1 net list").arg(m_sCliPath)); - processN.waitForFinished(-1); - QString result = QString::fromLatin1(processN.readAll()); - result.remove(' '); - if(!(result.isEmpty() || result.isNull() || result.contains('\''))) - { - list = result.remove("\n").remove("\r").split(":").at(1).split(","); - } + QStringList wallets; QProcess process; process.start(QString("%1 wallet list").arg(m_sCliPath)); @@ -119,69 +42,8 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q while (itr.hasNext()) { QRegularExpressionMatch match = itr.next(); - QString walletName = match.captured(1); - DapWallet wallet; - wallet.setName(walletName); - auto begin = list.begin(); - auto end = list.end(); - for(; begin != end; ++begin) - { - - wallet.addNetwork(*begin); - - QProcess process_token; - process_token.start(QString("%1 wallet info -w %2 -net %3") - .arg(m_sCliPath) - .arg(walletName) - .arg(*begin)); - - process_token.waitForFinished(-1); - QByteArray result_tokens = process_token.readAll(); - QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); - - int pos = 0; - DapWalletToken *token {nullptr}; - while((pos = regex.indexIn(result_tokens, pos)) != -1) - { - - if(!regex.cap(2).isEmpty()) - { - wallet.addAddress(regex.cap(2), *begin); - } - else - { - token = new DapWalletToken(); - token->setName(regex.cap(6).trimmed()); - token->setBalance(regex.cap(4).toDouble()); - QString str = regex.cap(5); - token->setEmission(regex.cap(5).toULongLong()); - token->setNetwork(*begin); - wallet.addToken(token); - } - - pos += regex.matchedLength(); - } - - } - wallets.append(wallet); + wallets.append(match.captured(1)); } - QByteArray datas; - QDataStream out(&datas, QIODevice::WriteOnly); - out << wallets; - - return QJsonValue::fromVariant(datas.toHex()); -} - - -/// Reply from service. -/// @details Performed on the service side. -/// @return Service reply. -QVariant DapGetListWalletsCommand::replyFromService() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - - emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); - - return reply->response().toJsonValue().toVariant(); + return wallets; } diff --git a/handlers/DapGetListWalletsCommand.h b/handlers/DapGetListWalletsCommand.h index 6d7c228279b0924143d02bfffbd2f3771fe2afc9..9805de41151c81d0f77cd7cea27289db5c0470ef 100644 --- a/handlers/DapGetListWalletsCommand.h +++ b/handlers/DapGetListWalletsCommand.h @@ -5,9 +5,6 @@ #include <QRegExp> #include <QRegularExpression> #include <QByteArray> -#include <QDataStream> -#include <QBuffer> -#include <QTextCodec> #include "DapWallet.h" #include "DapAbstractCommand.h" @@ -32,7 +29,6 @@ public slots: const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; - QVariant replyFromService() override; }; #endif // DAPGETLISTWALLETSCOMMAND_H diff --git a/handlers/DapGetWalletInfoCommand.cpp b/handlers/DapGetWalletInfoCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..689a0bcea059fc509c3ad0aa95c15b2ebcdba4f0 --- /dev/null +++ b/handlers/DapGetWalletInfoCommand.cpp @@ -0,0 +1,107 @@ +#include "DapGetWalletInfoCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetWalletInfoCommand::DapGetWalletInfoCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent, asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletInfoCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList list; + QProcess processGetNetworks; + processGetNetworks.start(QString("%1 net list").arg(m_sCliPath)); + processGetNetworks.waitForFinished(-1); + QString result = QString::fromLatin1(processGetNetworks.readAll()); + result.remove(' '); + if(!(result.isEmpty() || result.isNull() || result.contains('\''))) + { + list = result.remove("\n").remove("\r").split(":").at(1).split(","); + } + + DapWallet wallet; + wallet.setName(arg1.toString()); + auto begin = list.begin(); + auto end = list.end(); + for(; begin != end; ++begin) + { + + wallet.addNetwork(*begin); + + QProcess processGetTokkens; + processGetTokkens.start(QString("%1 wallet info -w %2 -net %3") + .arg(m_sCliPath) + .arg(wallet.getName()) + .arg(*begin)); + + processGetTokkens.waitForFinished(-1); + QByteArray result_tokens = processGetTokkens.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + DapWalletToken *token {nullptr}; + while((pos = regex.indexIn(result_tokens, pos)) != -1) + { + + if(!regex.cap(2).isEmpty()) + { + wallet.addAddress(regex.cap(2), *begin); + } + else + { + token = new DapWalletToken(); + token->setName(regex.cap(6).trimmed()); + token->setBalance(regex.cap(4).toDouble()); + QString str = regex.cap(5); + token->setEmission(regex.cap(5).toULongLong()); + token->setNetwork(*begin); + wallet.addToken(token); + } + + pos += regex.matchedLength(); + } + } + + QByteArray datas; + QDataStream out(&datas, QIODevice::WriteOnly); + out << wallet; + + return QJsonValue::fromVariant(datas.toHex()); +} + + +/// Reply from service. +/// @details Performed on the service side. +/// @return Service reply. +QVariant DapGetWalletInfoCommand::replyFromService() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + + emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); + + return reply->response().toJsonValue().toVariant(); +} + diff --git a/handlers/DapGetWalletInfoCommand.h b/handlers/DapGetWalletInfoCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..d92f5a09e1d3e3c4820103aea6a985d31e8bb2cf --- /dev/null +++ b/handlers/DapGetWalletInfoCommand.h @@ -0,0 +1,37 @@ +#ifndef DAPGETWALLETINFOCOMMAND_H +#define DAPGETWALLETINFOCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> +#include <QByteArray> +#include <QDataStream> +#include <QBuffer> +#include <QTextCodec> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetWalletInfoCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetWalletInfoCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; + QVariant replyFromService() override; +}; + +#endif // DAPGETWALLETINFOCOMMAND_H diff --git a/handlers/DapGetWalletsInfoCommand.cpp b/handlers/DapGetWalletsInfoCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a8b9d0a2f4d9a6aa5268e44ea0084395bce3a1a --- /dev/null +++ b/handlers/DapGetWalletsInfoCommand.cpp @@ -0,0 +1,121 @@ +#include "DapGetWalletsInfoCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetWalletsInfoCommand::DapGetWalletsInfoCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent, asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletsInfoCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QList<DapWallet> wallets; + + QStringList list; + QProcess processN; + processN.start(QString("%1 net list").arg(m_sCliPath)); + processN.waitForFinished(-1); + QString result = QString::fromLatin1(processN.readAll()); + result.remove(' '); + if(!(result.isEmpty() || result.isNull() || result.contains('\''))) + { + list = result.remove("\n").remove("\r").split(":").at(1).split(","); + } + + QProcess process; + process.start(QString("%1 wallet list").arg(m_sCliPath)); + process.waitForFinished(-1); + QString res = QString::fromLatin1(process.readAll()); + QRegularExpression rx("wallet:\\s(.+)\\s", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(res); + while (itr.hasNext()) + { + QRegularExpressionMatch match = itr.next(); + QString walletName = match.captured(1); + DapWallet wallet; + wallet.setName(walletName); + auto begin = list.begin(); + auto end = list.end(); + for(; begin != end; ++begin) + { + + wallet.addNetwork(*begin); + + QProcess process_token; + process_token.start(QString("%1 wallet info -w %2 -net %3") + .arg(m_sCliPath) + .arg(walletName) + .arg(*begin)); + + process_token.waitForFinished(-1); + QByteArray result_tokens = process_token.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + DapWalletToken *token {nullptr}; + while((pos = regex.indexIn(result_tokens, pos)) != -1) + { + + if(!regex.cap(2).isEmpty()) + { + wallet.addAddress(regex.cap(2), *begin); + } + else + { + token = new DapWalletToken(); + token->setName(regex.cap(6).trimmed()); + token->setBalance(regex.cap(4).toDouble()); + QString str = regex.cap(5); + token->setEmission(regex.cap(5).toULongLong()); + token->setNetwork(*begin); + wallet.addToken(token); + } + + pos += regex.matchedLength(); + } + + } + wallets.append(wallet); + } + + QByteArray datas; + QDataStream out(&datas, QIODevice::WriteOnly); + out << wallets; + + return QJsonValue::fromVariant(datas.toHex()); +} + + +/// Reply from service. +/// @details Performed on the service side. +/// @return Service reply. +QVariant DapGetWalletsInfoCommand::replyFromService() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + + emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); + + return reply->response().toJsonValue().toVariant(); +} diff --git a/handlers/DapGetWalletsInfoCommand.h b/handlers/DapGetWalletsInfoCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..75cdd97492d9a889c826e89321cdbfb5139cd1b4 --- /dev/null +++ b/handlers/DapGetWalletsInfoCommand.h @@ -0,0 +1,38 @@ +#ifndef DAPGETWALLETSINFOCOMMAND_H +#define DAPGETWALLETSINFOCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> +#include <QByteArray> +#include <QDataStream> +#include <QBuffer> +#include <QTextCodec> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetWalletsInfoCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetWalletsInfoCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; + QVariant replyFromService() override; +}; + +#endif // DAPGETWALLETSINFOCOMMAND_H diff --git a/handlers/DapQuitApplicationCommand.h b/handlers/DapQuitApplicationCommand.h index c40ae937f79d7ea8d27010ca7f5269078bd22083..3eaa3a8055bd1f1f7d13ea5cbd0fad7076578c08 100644 --- a/handlers/DapQuitApplicationCommand.h +++ b/handlers/DapQuitApplicationCommand.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** This file is part of the libCellFrameDashboardClient library. +** This file is part of the libdap-qt-ui-chain-wallet library. ** ** The class implements the exit command of the application. Both the ** GUI client and the service complete the work. diff --git a/libdap-qt-ui-chain-wallet.pri b/libdap-qt-ui-chain-wallet.pri index 47ae284e733f5454f44db28a65cb73f48a47afd2..4c668167070132eb756eff2f3b3fbb2b6db40c2b 100644 --- a/libdap-qt-ui-chain-wallet.pri +++ b/libdap-qt-ui-chain-wallet.pri @@ -30,8 +30,10 @@ HEADERS += \ $$PWD/handlers/DapGetHistoryExecutedCmdCommand.h \ $$PWD/handlers/DapGetListNetworksCommand.h \ $$PWD/handlers/DapGetListWalletsCommand.h \ + $$PWD/handlers/DapGetWalletsInfoCommand.h \ $$PWD/handlers/DapGetWalletAddressesCommand.h \ $$PWD/handlers/DapGetWalletHistoryCommand.h \ + $$PWD/handlers/DapGetWalletInfoCommand.h \ $$PWD/handlers/DapGetWalletTokenInfoCommand.h \ $$PWD/handlers/DapMempoolProcessCommand.h \ $$PWD/handlers/DapQuitApplicationCommand.h \ @@ -63,8 +65,10 @@ SOURCES += \ $$PWD/handlers/DapGetHistoryExecutedCmdCommand.cpp \ $$PWD/handlers/DapGetListNetworksCommand.cpp \ $$PWD/handlers/DapGetListWalletsCommand.cpp \ + $$PWD/handlers/DapGetWalletsInfoCommand.cpp \ $$PWD/handlers/DapGetWalletAddressesCommand.cpp \ $$PWD/handlers/DapGetWalletHistoryCommand.cpp \ + $$PWD/handlers/DapGetWalletInfoCommand.cpp \ $$PWD/handlers/DapGetWalletTokenInfoCommand.cpp \ $$PWD/handlers/DapMempoolProcessCommand.cpp \ $$PWD/handlers/DapQuitApplicationCommand.cpp \ diff --git a/libdap-qt-ui-chain-wallet.qrc b/libdap-qt-ui-chain-wallet.qrc index 5aee0596244e02842a31830ff8a07702e11e6b91..b2b9c41577e45739344bda0d1c3bce150c789335 100644 --- a/libdap-qt-ui-chain-wallet.qrc +++ b/libdap-qt-ui-chain-wallet.qrc @@ -14,5 +14,6 @@ <file>resources/fonts/roboto_regular.ttf</file> <file>resources/fonts/roboto_thin_italic.ttf</file> <file>resources/fonts/roboto_thin.ttf</file> + <file>resources/JS/TimeFunctions.js</file> </qresource> </RCC> diff --git a/resources/JS/TimeFunctions.js b/resources/JS/TimeFunctions.js new file mode 100644 index 0000000000000000000000000000000000000000..6084d72e283b92184ab0a05e5f7b35ba9441ba70 --- /dev/null +++ b/resources/JS/TimeFunctions.js @@ -0,0 +1,60 @@ +//Splits a string from the log. +function parceStringFromLog(string) +{ + var split = string.split(/ \[|\] \[|\]|\[/); + return split; +} + + +//This function converts the string representation of time to the Date format +function parceTime(thisTime) +{ + var aDate = thisTime.split('-'); + var aDay = aDate[0].split('/'); + var aTime = aDate[1].split(':'); + return new Date(20+aDay[2], aDay[0] - 1, aDay[1], aTime[0], aTime[1], aTime[2]); +} + + +//Returns the time in the correct form +function getTime(thisTime) +{ + var tmpTime = new Date(thisTime) + var thisHour = tmpTime.getHours(); + var thisMinute = tmpTime.getMinutes(); + var thisSecond = tmpTime.getSeconds(); + if(thisMinute < 10) thisMinute = '0' + thisMinute; + if(thisSecond < 10) thisSecond = '0' + thisSecond; + return thisHour + ':' + thisMinute + ':' + thisSecond; +} + + +//Returns the time in the correct form for the header +function getDay(thisTime, privateDate) +{ + var monthArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December"]; + var tmpDate = new Date(thisTime); + var thisMonth = tmpDate.getMonth(); + var thisDay = tmpDate.getDate(); + var thisYear = tmpDate.getFullYear(); + + if(thisYear === privateDate.todayYear) + { + if(thisMonth === privateDate.todayMonth) + { + switch(thisDay) + { + case(privateDate.todayDay): return"Today"; + case(privateDate.todayDay-1): return"Yesterday"; + default: return monthArray[thisMonth] + ', ' + thisDay; + } + } + else + return monthArray[thisMonth] + ', ' + thisDay; + } + else + return monthArray[thisMonth] + ', ' + thisDay + ', ' + thisYear; +} + +