diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..ad8d1fe6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets" : ["es2015", "react"] +} diff --git a/.editorconfig b/.editorconfig index 821d3ad5..6a6b1f42 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,17 +4,15 @@ root = true # Unix-style newlines with a newline ending every file - [**] end_of_line = lf insert_final_newline = true - # Standard at: https://github.com/felixge/node-style-guide - [**.js, **.json] trim_trailing_whitespace = true indent_style = tab +indent_size = 4 quote_type = single curly_bracket_next_line = false spaces_around_operators = true @@ -23,9 +21,6 @@ space_after_anonymous_functions = false spaces_in_brackets = false tab_size= 4 - # No standard. Please document a standard if different from .js - [**.md] indent_style = tab - diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..f0c942b5 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,30 @@ +env: + browser: true + commonjs: true + es6: true + node: true +extends: 'eslint:recommended' +globals: + ga: true +parserOptions: + ecmaFeatures: + experimentalObjectRestSpread: true + jsx: true + sourceType: module +plugins: + - react +rules: + linebreak-style: + - error + - unix + quotes: + - error + - single + semi: + - error + - always + curly: error + eqeqeq: error + no-empty: warn + no-console: off + no-unused-vars: off diff --git a/.jsbeautifyrc b/.jsbeautifyrc deleted file mode 100644 index db7b8f58..00000000 --- a/.jsbeautifyrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "js": { - "indent_size": 4 - } -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index ec081e3a..00000000 --- a/.jshintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "node": true, // Enable globals available when code is running inside of the NodeJS runtime environment. - "curly": false, // Require {} for every new block or scope. - "eqeqeq": true, // Require triple equals i.e. `===`. - "immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` - "latedef": true, // Prohibit variable use before definition. - "newcap": false, // Require capitalization of all constructor functions e.g. `new F()`. - "noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`. - "quotmark": "single", // Define quotes to string values. - "regexp": true, // Prohibit `.` and `[^...]` in regular expressions. - "undef": true, // Require all non-global variables be declared before they are used. - "strict": true, // Require `use strict` pragma in every file. - "indent": 4, // Specify indentation spacing - "devel": true, // Allow development statements e.g. `console.log();`. - "noempty": true, // Prohibit use of empty blocks. - "esnext" : true, - "browser":true -} diff --git a/app/controllers/alerts/notifications.js b/app/controllers/alerts/notifications.js deleted file mode 100644 index 46e7d30f..00000000 --- a/app/controllers/alerts/notifications.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -var Joi = require('joi'); -var _ = require('lodash'); -var Notifier = require('../../helpers/notifier'); - -exports.showUnreadNotifications = { - description: 'Show unread notifications', - handler: function(request, reply) { - - // var db = request.server.plugins.sequelize.db; - // var notifications = request.server.plugins.sequelize.db.notifications; - var ctx = { - notifications: [] - }; - // notifications.findAll({ - // where: { - // user_id: request.auth.credentials.id, - // viewed: 0 - // } - - // }).then(function(unread) { - - // unread.forEach(function(n) { - // n.dataValues.msg = Notifier.message(n, request); - // }); - - // ctx.notifications = _.groupBy(unread, function(n) { - // return n.batch_id; - // }); - - // notifications.update({ - // viewed: 1 - // }, { - // where: { - // user_id: request.auth.credentials.id, - // viewed: 0 - // } - // }); - reply.view('alerts/notifications-unread', ctx); - // }); - - } -}; - -exports.showReadNotifications = { - description: 'Show notifications', - handler: function(request, reply) { - - // var db = request.server.plugins.sequelize.db; - // var notifications = request.server.plugins.sequelize.db.notifications; - var ctx = { - notifications: [] - }; - - // notifications.findAll({ - // where: { - // user_id: request.auth.credentials.id, - // viewed: 1 - // } - // }).then(function(read) { - - // read.forEach(function(n) { - // n.dataValues.msg = Notifier.message(n, request); - // }); - - // ctx.notifications = _.groupBy(read, function(n) { - // return n.batch_id; - // }); - - reply.view('alerts/notifications-read', ctx); - // }); - - } -}; diff --git a/app/controllers/api/account.js b/app/controllers/api/account.js new file mode 100644 index 00000000..b1383dec --- /dev/null +++ b/app/controllers/api/account.js @@ -0,0 +1,64 @@ +'use strict'; + +const Joi = require('joi'); +const Boom = require('boom'); +const Crypto = require('crypto'); + +exports.postChangePassword = { + description: 'Password change api', + validate: { + payload: { + oldPassword: Joi.string().min(6).max(20).required(), + newPassword: Joi.string().min(6).max(20).required(), + verify: Joi.string().required(), + }, + failAction: function(request, reply, source, error) { + // Boom bad request + return reply(Boom.badRequest(error)); + } + }, + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false + } + }, + handler: function(request, reply) { + + if (!request.auth.isAuthenticated) { + return Boom.forbidden('You are not logged in'); + } + + if (request.payload.newPassword !== request.payload.verify) { + return reply(Boom.badRequest('New password does not match')); + } + var User = request.server.plugins.sequelize.db.User; + + User.findOne({ + where: { + username: request.auth.credentials.username, + password: Crypto.createHash('md5').update(request.payload.oldPassword).digest('hex') + } + }).then(function(user) { + if (user) { + user.update({ + password: Crypto.createHash('md5').update(request.payload.newPassword).digest('hex') + }).then(function() { + request.cookieAuth.clear(); + + var msg = { + 'statusCode': 200, + 'message': 'Password changed successfully. Please login with new password' + }; + return reply(msg); + }); + } else { + // User not fond in database + return reply(Boom.badRequest('Old password is incorrect')); + } + }); + } +}; diff --git a/app/controllers/api/cards.js b/app/controllers/api/cards.js index 524873d8..01440fa3 100644 --- a/app/controllers/api/cards.js +++ b/app/controllers/api/cards.js @@ -1,205 +1,48 @@ 'use strict'; -var d3 = require('d3'); -var queries = require('../../helpers/queries'); -var utils = require('../../helpers/utils'); - +const Queries = require('../../helpers/queries'); +const Parser = require('../../helpers/paydroid_parser'); +const Boom = require('boom'); exports.getData = { - plugins: { - 'crumb': { - skip: true + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false } }, handler: function(request, reply) { + if (!request.auth.isAuthenticated) { + return reply(Boom.forbidden('You are not logged in')); + } + var sequelize = request.server.plugins.sequelize.db.sequelize; var userId = request.auth.credentials.id; + var role = request.auth.credentials.role; + var version = request.pre.apiVersion; - var queryString = queries.cards(userId); + var queryString = Queries.paydroid(userId, role, version); // API CODE - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - - var overviewResponse = utils.flatten(rows[0]); - - var cardsResponse = utils.flatten(rows[1]); - - var blockResponse = utils.flatten(rows[2]); - - var panchayatResponse = utils.flatten(rows[3]); - - var stateResponse = utils.flatten(rows[4]); - - var contactResponse = utils.flatten(rows[5]); - - // Parse the overview response - var current_total = overviewResponse[0].current_total; - var delayed_total = overviewResponse[0].delayed_total; - var days_to_payment = overviewResponse[0].time_to_payment; - var total_transactions = overviewResponse[0].total_transactions; - - var state_code = stateResponse[0].state_code; - - // Nest the cards response and include the overview stats - var cards = d3.nest() - .key(function(d) { - var key = d.staff_id + d.block_code; - return key; - }) - .rollup(function(v) { - return { - 'name': v[0].name, - 'staff_id': v[0].staff_id, - 'designation': utils.getDesignation(v[0].task_assign,state_code), - 'mobile':v[0].mobile_no, - 'block_name':v[0].block_name, - 'current_total':v[0].current_total, - 'delayed_total':v[0].delayed_total, - 'delayed_musters': v.filter(function(d) { return d.type==='delayed_musters'; }).map(function(d) { - return [ - { - 'msr_no':d.msr_no, - 'panchayat_name':d.panchayat_name, - 'work_name':d.work_name, - 'work_code':d.work_code, - 'closure_date':d.end_date, - 'days_pending':d.days_pending - } - ]; - }), - 'current_musters': v.filter(function(d) { return d.type==='current_musters'; }).map(function(d) { - return [ - { - 'msr_no':d.msr_no, - 'panchayat_name':d.panchayat_name, - 'work_name':d.work_name, - 'work_code':d.work_code, - 'closure_date':d.end_date - } - ]; - }) - }; - }) - .entries(cardsResponse) - .map(function(d) { - return d.values; - }); - - - // Nest the block response - var blockPerformance = d3.nest() - .key(function(d) { - return d.block_code; - }) - .rollup(function(v) { - return { - 'block_code': v[0].block_code, - 'block_name': v[0].block_name, - 'data': v.map(function(d) { - return [ - d.date.getFullYear() + '' + utils.padNum(d.date.getMonth() + 1) + '' + utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - }) - .entries(blockResponse) - .map(function(d) { - return d.values; - }) - .sort(function(a, b) { - var aTarget = a.data[a.data.length - 1]; - var bTarget = b.data[b.data.length - 1]; - var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; - var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; - return bSum - aSum; - }); - + sequelize.query(queryString, { + type: sequelize.QueryTypes.SELECT + }).then(function(rows) { - // Nest the panchayat response - var panchayatPerformance = d3.nest() - .key(function(d) { - return d.panchayat_code; - }) - .rollup(function(v) { - return { - 'block_code': v[0].block_code, - 'panchayat_code': v[0].panchayat_code, - 'panchayat_name': v[0].panchayat_name, - 'data': v.map(function(d) { - return [ - d.date.getFullYear() + '' + utils.padNum(d.date.getMonth() + 1) + '' + utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - }) - .entries(panchayatResponse) - .map(function(d) { - return d.values; - }) - .sort(function(a, b) { - var aTarget = a.data[a.data.length - 1]; - var bTarget = b.data[b.data.length - 1]; - var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; - var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; - return bSum - aSum; - }); + var data; - var headers = ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn']; + if (version === 1) { + data = Parser.v1(rows); + } else if (version === 2) { + data = Parser.v2(rows, role); + } - var data = { - 'overview': { - 'current_total':current_total, - 'delayed_total':delayed_total, - 'days_to_payment':days_to_payment, - 'total_transactions':total_transactions, - 'cards_total': cards.length - }, - 'cards': cards, - 'block_performance': blockPerformance, - 'panchayat_performance': panchayatPerformance, - 'notifications': [], - 'config': { - 'headers': headers, - labels: [ - 'Date', - 'Muster roll closure to muster roll entry', - 'Muster roll entry to wage list generation', - 'Wage list generation to wage list sent', - 'Wage list sent to FTO generation', - 'FTO generation to first signature', - 'First signature to second signature', - 'Second signature to processed by bank', - 'Total Transactions' - ], - }, - 'contact': { - 'phone': contactResponse[0].phone, - 'email': contactResponse[0].email, - 'subject': contactResponse[0].subject - } - }; + reply(data); - reply(data); - }); + }); } -}; +}; \ No newline at end of file diff --git a/app/controllers/api/login.js b/app/controllers/api/login.js index 1a23fb23..5f9ec4d7 100644 --- a/app/controllers/api/login.js +++ b/app/controllers/api/login.js @@ -4,9 +4,6 @@ var Boom = require('boom'); var Joi = require('joi'); var crypto = require('crypto'); -var lockoutInterval = 60; // seconds -var maxAttemptsBeforeLockout = 5; - exports.postForm = { description: 'Post to the login page', auth: { @@ -21,7 +18,8 @@ exports.postForm = { validate: { payload: { // payload for POST, query for GET username: Joi.string().min(3).max(20), - password: Joi.string().min(6).max(20) + password: Joi.string().min(6).max(20), + google_account: Joi.string().min(6).max(60).optional() }, failAction: function(request, reply, source, error) { // Username, passowrd minimum validation failed @@ -39,12 +37,47 @@ exports.postForm = { password: crypto.createHash('md5').update(request.payload.password).digest('hex') } }).then(function(user) { - if (user) { - request.auth.session.set(user); + + // If user account is deactivated + if (user && user.deactivated) { + return reply(Boom.badRequest('User account deactivated')); + } + + // If user is test or pilot + else if (user && user.type === 'test' || user.type === 'pilot_one') { + request.cookieAuth.set(user); delete user.password; return reply(user); - } else { - // User not fond in database + } + + // If user has correct google account info + else if (user && user.google_account === request.payload.google_account) { + request.cookieAuth.set(user); + delete user.password; + return reply(user); + + } + + // If user does not have google account + else if (user && !user.google_account) { + + user.update({ google_account: request.payload.google_account }).then(function(user) { + request.cookieAuth.set(user); + delete user.password; + return reply(user); + }); + } + + // If gogole account info provided is not same as user's + else if (user && user.google_account && (user.google_account !== request.payload.google_account)) { + + return reply(Boom.badRequest('Google account does not match')); + + } + + // User not fond in database + else { + return reply(Boom.badRequest('Invalid username or password')); } }); diff --git a/app/controllers/api/logout.js b/app/controllers/api/logout.js index 0943f4eb..35b67959 100644 --- a/app/controllers/api/logout.js +++ b/app/controllers/api/logout.js @@ -4,10 +4,17 @@ var Boom = require('boom'); exports.postForm = { auth: { + mode: 'try', strategy: 'standard' }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false + } + }, handler: function(request, reply) { - request.auth.session.clear(); + + request.cookieAuth.clear(); return reply({ "statusCode": 200, diff --git a/app/controllers/api/notifications.js b/app/controllers/api/notifications.js deleted file mode 100644 index 8cdbb2b7..00000000 --- a/app/controllers/api/notifications.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var Joi = require('joi'); -var _ = require('lodash'); -var Notifier = require('../../helpers/notifier'); - -exports.showUnreadNotifications = { - description: 'Show unread notifications', - handler: function(request, reply) { - - var db = request.server.plugins.sequelize.db; - var notifications = request.server.plugins.sequelize.db.notifications; - - notifications.findAll({ - where: { - user_id: request.auth.credentials.id, - viewed: 0 - } - - }).then(function(unread) { - - unread.forEach(function(n) { - n.dataValues.msg = Notifier.message(n, request); - }); - - notifications.update({ - viewed: 1 - }, { - where: { - user_id: request.auth.credentials.id, - viewed: 0 - } - }); - reply(unread); - }); - - } -}; - -exports.showReadNotifications = { - description: 'Show notifications', - handler: function(request, reply) { - - var db = request.server.plugins.sequelize.db; - var notifications = request.server.plugins.sequelize.db.notifications; - - notifications.findAll({ - where: { - user_id: request.auth.credentials.id, - viewed: 1 - } - }).then(function(read) { - - read.forEach(function(n) { - n.dataValues.msg = Notifier.message(n, request); - }); - - reply(read); - }); - - } -}; diff --git a/app/controllers/api/profile.js b/app/controllers/api/profile.js index 9e33ba0e..f6e709f5 100644 --- a/app/controllers/api/profile.js +++ b/app/controllers/api/profile.js @@ -1,39 +1,42 @@ 'use strict'; var Joi = require('joi'); +var Boom = require('boom'); exports.postEditProfile = { description: 'Post Edit profile settings', validate: { payload: { - firstname: Joi.string().min(2).max(20).required(), - lastname: Joi.string().min(2).max(20).required(), - gender: Joi.string().max(100).required(), - dob: Joi.string().max(100).allow(''), mobile: Joi.string().max(100).allow(''), email: Joi.string().max(100).allow(''), - sas: Joi.string().allow(''), - sas_years: Joi.string().max(100).allow(''), - ias: Joi.string().allow(''), - ias_years: Joi.string().max(100).allow(''), - title: Joi.string().max(100).allow(''), - region_type: Joi.string().max(100).allow(''), - region_name: Joi.string().max(100).allow(''), work_email: Joi.string().max(100).allow(''), - work_years: Joi.string().max(100).allow(''), - time_on_nrega: Joi.string().max(100).allow('') + lang: Joi.string().min(1).max(10), + colorblind: Joi.boolean() }, failAction: function(request, reply, source, error) { // Boom bad request return reply.reply(Boom.badRequest(error)); } }, + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false + } + }, handler: function(request, reply) { + if (!request.auth.isAuthenticated) { + return Boom.forbidden('You are not logged in'); + } + var id = request.auth.credentials.id.toString(); request.payload.updated_at = Date.now(); - var User = request.server.plugins.sequelize.db.users; + var User = request.server.plugins.sequelize.db.User; User.findOne({ where: { id: id @@ -41,8 +44,8 @@ exports.postEditProfile = { }).then(function(user) { if (user) { // if the record exists in the db user.update(request.payload).then(function() { - request.auth.session.clear(); - request.auth.session.set(user); + request.cookieAuth.clear(); + request.cookieAuth.set(user); return reply(user); }); diff --git a/app/controllers/api/translate.js b/app/controllers/api/translate.js index 1edba949..2772dc87 100644 --- a/app/controllers/api/translate.js +++ b/app/controllers/api/translate.js @@ -3,21 +3,32 @@ var queries = require('../../helpers/queries'); var utils = require('../../helpers/utils'); var Translate = require('../../templates/helpers/t'); +var Boom = require('boom'); exports.getData = { + auth: { + mode: 'try', + strategy: 'standard' + }, plugins: { - 'crumb': { - skip: true + 'hapi-auth-cookie': { + redirectTo: false } }, handler: function(request, reply) { - var res = { - en_US: Translate('/app', { lang: 'en_US' }), - hi: Translate('/app', { lang: 'hi' }) + if (!request.auth.isAuthenticated) { + return reply(Boom.forbidden('You are not logged in')); } + + var version = request.pre.apiVersion; + var res = { + en_US: Translate('/app', { lang: 'en_US', role: request.auth.credentials.role }, version), + hi: Translate('/app', { lang: 'hi', role: request.auth.credentials.role }, version) + }; + reply(res); } diff --git a/app/controllers/auth/login.js b/app/controllers/auth/login.js index 850c622e..9d7346f6 100644 --- a/app/controllers/auth/login.js +++ b/app/controllers/auth/login.js @@ -1,12 +1,8 @@ 'use strict'; -var Boom = require('boom'); -var Joi = require('joi'); -var crypto = require('crypto'); - -var lockoutInterval = 60; // seconds -var maxAttemptsBeforeLockout = 5; - +const Boom = require('boom'); +const Joi = require('joi'); +const Crypto = require('crypto'); exports.showForm = { description: 'Returns the login page', @@ -22,7 +18,7 @@ exports.showForm = { handler: function(request, reply) { if (request.auth.isAuthenticated) { - return reply.redirect('/performance/overview'); + return reply.redirect('/overview'); } reply.view('auth/login'); @@ -52,39 +48,47 @@ exports.postForm = { }, failAction: function(request, reply, source, error) { // Username, passowrd minimum validation failed - request.session.flash('error', 'Invalid username or password'); + request.yar.flash('error', 'Invalid username or password'); return reply.redirect('/login'); }, }, handler: function(request, reply) { if (request.auth.isAuthenticated) { - return reply.redirect('/performance/overview'); + return reply.redirect('/overview'); } + var db = request.server.plugins.sequelize.db; var User = request.server.plugins.sequelize.db.User; User.findOne({ where: { username: request.payload.username, - password: crypto.createHash('md5').update(request.payload.password).digest('hex') + password: Crypto.createHash('md5').update(request.payload.password).digest('hex') }, include: [db.user_regions] }).then(function(user) { if (user) { - request.auth.session.set(user); + + if(user.deactivated){ + request.yar.flash('error', 'Your account has been deactivated. Please contact the PayDash team if you require assistance.'); + return reply.redirect('/login'); + } + + request.cookieAuth.set(user); + if (!user.isActive) { - request.session.flash('info', 'Please check your profile details'); + request.yar.flash('info', 'Please check your profile details'); user.update({ isActive: true }).then(function() { return reply.redirect('/me/settings/profile'); }); } else { - return reply.redirect('/performance/overview'); + return reply.redirect('/overview'); } } else { // User not fond in database - request.session.flash('error', 'Invalid username or password'); + request.yar.flash('error', 'Invalid username or password'); return reply.redirect('/login'); } }); diff --git a/app/controllers/auth/logout.js b/app/controllers/auth/logout.js index 187acdf9..f7bea8df 100644 --- a/app/controllers/auth/logout.js +++ b/app/controllers/auth/logout.js @@ -13,8 +13,8 @@ module.exports = { }, handler: function(request, reply) { - request.auth.session.clear(); - request.session.flash('success', 'Logged out successfully'); + request.cookieAuth.clear(); + request.yar.flash('success', 'Logged out successfully'); return reply.redirect('/login'); } diff --git a/app/controllers/auth/password-forgot.js b/app/controllers/auth/password-forgot.js new file mode 100644 index 00000000..dbc3e1ec --- /dev/null +++ b/app/controllers/auth/password-forgot.js @@ -0,0 +1,92 @@ +'use strict'; + +const Crypto = require('crypto'); +const Joi = require('joi'); + +exports.showRecoveryForm = { + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false // To stop from redirect loop + } + }, + handler: function(request, reply) { + + reply.view('auth/password-recovery'); + + } +}; + +exports.postRecoveryForm = { + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false // To stop from redirect loop + } + }, + validate: { + payload: { + name_email: Joi.string().min(2).max(20).required() + }, + failAction: function(request, reply, source, error) { + // Boom bad request + request.session.flash('error', 'Bad request'); + return reply.redirect('/me/settings/profile'); + } + }, + handler: function(request, reply) { + // Generate Token + Crypto.randomBytes(20, function(err, buffer) { + + var token = buffer.toString('hex'); + var query = {}; + if (request.payload.name_email.indexOf('@') > -1) { + query.email = request.payload.name_email.toLowerCase(); + } else { + query.username = request.payload.name_email.toLowerCase(); + } + + var User = request.server.plugins.sequelize.db.User; + + // Find User by username or email + User.findOne({ + where : query + }).then(function(user) { + + if(user){ + user.update({ + reset_password_token : token, + reset_password_expires : Date.now() + 3600000 + }).then(function(){ + var data = { + from: 'epodindianrega@gmail.com', + to: user.email, + subject: 'Password Reset - PayDash', + path: 'emails/forgot-password', + context: { + name: user.firstname + ' ' + user.lastname, + url: request.connection.info.protocol + '://' + request.info.host + '/reset-password/' + token + } + }; + // Send Email + var Mailer = request.server.plugins.mailer; + Mailer.sendMail(data, function(err, info) { + // Email Sent + }); + request.yar.flash('success', 'An email has sent to your registered email id with password reset instructions'); + return reply.redirect('/forgot-password'); + }); + } else { + request.yar.flash('error', 'Invalid username or email'); + } + }); + }); + + } +}; diff --git a/app/controllers/auth/password-reset.js b/app/controllers/auth/password-reset.js new file mode 100644 index 00000000..c52a49af --- /dev/null +++ b/app/controllers/auth/password-reset.js @@ -0,0 +1,110 @@ +'use strict'; + +var Crypto = require('crypto'); +var Joi = require('joi'); + +exports.showResetForm = { + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false // To stop from redirect loop + } + }, + validate: { + params: { + token: Joi.string().min(2) + }, + failAction: function(request, reply, source, error) { + // Boom bad request + request.yar.flash('error', 'Invalid Token'); + return reply.redirect('/reset-password'); + } + }, + handler: function(request, reply) { + + var ctx = {}; + var User = request.server.plugins.sequelize.db.User; + User.findOne({ + where: { + reset_password_token: request.params.token, + reset_password_expires: { + $gt: Date.now() + } + } + }).then(function(user) { + if (user) { + ctx.isValidToken = true; + return reply.view('auth/password-reset', ctx); + } else { + ctx.isValidToken = false; + return reply.view('auth/password-reset', ctx); + } + + }); + + } +}; + +exports.postResetForm = { + auth: { + mode: 'try', + strategy: 'standard' + }, + plugins: { + 'hapi-auth-cookie': { + redirectTo: false // To stop from redirect loop + } + }, + validate: { + payload: { + password: Joi.string().min(2).max(20).required(), + verify: Joi.string().min(2).max(20).required() + }, + params: { + token: Joi.string().min(2) + }, + failAction: function(request, reply, source, error) { + // Boom bad request + request.yar.flash('error', 'Bad request'); + return reply.redirect('/reset-password'); + } + }, + handler: function(request, reply) { + + if (request.payload.password !== request.payload.verify) { + request.yar.flash('error', ' New Password does not match'); + return reply.redirect('/reset-password'); + } + var User = request.server.plugins.sequelize.db.User; + User.findOne({ + where: { + reset_password_token: request.params.token, + reset_password_expires: { + $gt: Date.now() + } + } + }).then(function(user) { + if (user) { + user.update({ + password : Crypto.createHash('md5').update(request.payload.password).digest('hex'), + reset_password_token: null, + reset_password_expires: null + }).then(function() { + request.yar.flash('success', 'Password changed successfully. Please login with new password'); + // TODO : Send password change email + request.cookieAuth.clear(); + return reply.redirect('/login'); + }); + } else { + // User not fond in database + request.yar.flash('error', 'Token is invalid'); + return reply.redirect('/reset-password'); + } + }); + + + } +}; diff --git a/app/controllers/contact/contact.js b/app/controllers/contact/contact.js new file mode 100644 index 00000000..e1f5bbc8 --- /dev/null +++ b/app/controllers/contact/contact.js @@ -0,0 +1,31 @@ +'use strict'; + +const Queries = require('../../helpers/queries'); +const D3 = require('d3'); +const Utils = require('../../helpers/utils'); + + +exports.getData = { + handler: function(request, reply) { + + var sequelize = request.server.plugins.sequelize.db.sequelize; + var userId = request.auth.credentials.id; + var queryString = Queries.contact(userId); + + sequelize.query(queryString, { + type: sequelize.QueryTypes.SELECT + }).then(function(rows) { + + var contactResponse = D3.values(rows[0]); + var regionsResponse = D3.values(rows[1]); + + var subjectLine = Utils.buildSubject(contactResponse[0].subject, regionsResponse); + var data = { + 'phone': contactResponse[0].phone, + 'email': contactResponse[0].email, + 'subject': subjectLine + }; + reply.view('contact/contact', {info: data}); + }); + } +}; diff --git a/app/controllers/monitor/analysis.js b/app/controllers/monitor/analysis.js deleted file mode 100644 index 44fcc0fe..00000000 --- a/app/controllers/monitor/analysis.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -var queries = require('../../helpers/queries'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('monitor/analysis', null, { - layout: 'monitor' - }); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var queryString = queries.outcomes(); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(data) { - - var results = []; - var outcomes = data[0]; - var treatments = data[1]; - var summary = data[2]; - var arms = data[3]; - var arm_summary = data[4]; - - for (var index in outcomes) { - - var result = { - treatment: [], - control: [], - arm_1: [], - arm_2: [], - arm_3: [] - }; - result.label = outcomes[index].label; - result.name = outcomes[index].outcome; - for (var treatment_index in treatments) { - treatments[treatment_index].value = treatments[treatment_index].mean; - if (treatments[treatment_index].outcome === outcomes[index].outcome && treatments[treatment_index].treatment === 1) { - result.treatment.push(treatments[treatment_index]); - } - if (treatments[treatment_index].outcome === outcomes[index].outcome && treatments[treatment_index].treatment === 0) { - result.control.push(treatments[treatment_index]); - } - } - for (var arm_index in arms) { - arms[arm_index].value = arms[arm_index].mean; - if (arms[arm_index].outcome === outcomes[index].outcome && arms[arm_index].arm === 1) { - result.arm_1.push(arms[arm_index]); - } - if (arms[arm_index].outcome === outcomes[index].outcome && arms[arm_index].arm === 2) { - result.arm_2.push(arms[arm_index]); - } - if (arms[arm_index].outcome === outcomes[index].outcome && arms[arm_index].arm === 3) { - result.arm_3.push(arms[arm_index]); - } - } - for (var stat_index in summary) { - if (summary[stat_index].outcome === outcomes[index].outcome) { - result.summary = summary[stat_index]; - } - } - for (var arm_stat_index in arm_summary) { - if (arm_summary[arm_stat_index].outcome === outcomes[index].outcome) { - result.arm_summary = arm_summary[arm_stat_index]; - } - } - results.push(result); - } - - reply(results); - }); - } -}; diff --git a/app/controllers/monitor/server.js b/app/controllers/monitor/server.js deleted file mode 100644 index a1c57533..00000000 --- a/app/controllers/monitor/server.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -var path = require('path'); -var readline = require('readline'); -var fs = require('fs'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('monitor/server', null, { - layout: 'monitor' - }); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var stats = []; - var statPath = path.resolve(__dirname + '/../../../logs/stats/stats.log'); - var lineReader = readline.createInterface({ - input: fs.createReadStream(statPath) - }); - - lineReader.on('line', function(line) { - stats.push(JSON.parse(line)); - }); - - lineReader.on('close', function() { - reply(stats); - }); - - } -}; - -exports.getPageLoadData = { - handler: function(request, reply) { - var analytics = request.server.plugins.ga.analytics; - var jwtClient = request.server.plugins.ga.jwtClient; - jwtClient.authorize(function(err, tokens) { - if (err) { - return; - } - - analytics.data.ga.get({ - auth: jwtClient, - 'ids': 'ga:73657543', - 'metrics': 'ga:avgPageLoadTime', - 'dimensions':'ga:date,ga:pagePath', - 'start-date': '2015-01-01', - 'end-date': '2016-01-16' - }, function(err, response) { - reply(response); - }); - - }); - } -}; diff --git a/app/controllers/monitor/user.js b/app/controllers/monitor/user.js deleted file mode 100644 index a1916609..00000000 --- a/app/controllers/monitor/user.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; -var d3 = require('d3'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('monitor/user', null, { - layout: 'monitor' - }); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var analytics = request.server.plugins.ga.analytics; - var jwtClient = request.server.plugins.ga.jwtClient; - jwtClient.authorize(function(err, tokens) { - if (err) { - return; - } - console.log('authenticated'); - analytics.data.ga.get({ - auth: jwtClient, - 'ids': 'ga:114514109', - 'metrics': 'ga:users,ga:sessionsPerUser,ga:pageviews,ga:sessions,ga:avgSessionDuration', - 'dimensions': 'ga:date', - 'start-date': '2015-12-18', - 'end-date': '2016-01-17' - }, function(err, response) { - console.log(response); - reply(response); - }); - - // analytics.data.ga.get({ - // auth: jwtClient, - // 'ids': 'ga:73657543', - // 'metrics': 'ga:pageviews,ga:avgTimeOnPage', - // 'dimensions':'ga:date,ga:pagePath', - // 'start-date': '2015-01-01', - // 'end-date': '2015-03-09' - // }, function(err, response) { - // console.log(response); - // }); - - }); - - - } -}; diff --git a/app/controllers/musters/current-musters.js b/app/controllers/musters/current-musters.js deleted file mode 100644 index 57b13e83..00000000 --- a/app/controllers/musters/current-musters.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var Queries = require('../../helpers/queries'); -var utils = require('../../helpers/utils'); -var req = require('request'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('musters/current'); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var active_region = request.query.active_region; - var queryString = Queries.current_musters(active_region); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - - var mustersResponse = utils.flatten(rows[0]); - var mappingResponse = utils.flatten(rows[1]); - - var final_dict = { - 'musters': mustersResponse.map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'grs':d.name, - 'mobile':d.mobile_no - }; - }), - 'mapping': { - 'total_panchayat_count': mappingResponse[0].total_panchayat_count, - 'grs_panchayat_count': mappingResponse[0].grs_panchayat_count, - } - - }; - - reply(final_dict); - }); - } -}; diff --git a/app/controllers/musters/delayed-musters.js b/app/controllers/musters/delayed-musters.js deleted file mode 100644 index 0ed479d7..00000000 --- a/app/controllers/musters/delayed-musters.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict'; - -var Queries = require('../../helpers/queries'); -var utils = require('../../helpers/utils'); -var req = require('request'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('musters/delayed'); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var active_region = request.query.active_region; - var queryString = Queries.delayed_musters(active_region); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - var mustersResponse = utils.flatten(rows[0]); - var mappingResponse = utils.flatten(rows[1]); - - var final_dict = { - 'musters': { - 'ds_t2': mustersResponse.filter(function(d) { return d.step==='ds_t2'; }).map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'closure_date':d.end_date, - 'days_pending':d.days_pending, - 'grs_name':d.name, - 'mobile':d.mobile_no - }; - }), - 'ds_t5': mustersResponse.filter(function(d) { return d.step==='ds_t5'; }).map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'closure_date':d.end_date, - 'days_pending':d.days_pending, - 'ta_name':d.name, - 'mobile':d.mobile_no - }; - }), - 'ds_t6': mustersResponse.filter(function(d) { return d.step==='ds_t6'; }).map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'closure_date':d.end_date, - 'days_pending':d.days_pending - }; - }), - 'ds_t7': mustersResponse.filter(function(d) { return d.step==='ds_t7'; }).map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'closure_date':d.end_date, - 'days_pending':d.days_pending - }; - }), - 'ds_t8': mustersResponse.filter(function(d) { return d.step==='ds_t8'; }).map(function(d) { - return { - 'msr_no':d.msr_no, - 'work':d.work_name, - 'panchayat':d.panchayat_name, - 'closure_date':d.end_date, - 'days_pending':d.days_pending - }; - }) - - }, - 'mapping': { - 'total_panchayat_count': mappingResponse[0].total_panchayat_count, - 'grs_panchayat_count': mappingResponse[0].grs_panchayat_count, - 'ta_panchayat_count': mappingResponse[0].ta_panchayat_count - } - - }; - - reply(final_dict); - }); - } -}; diff --git a/app/controllers/musters/musters.js b/app/controllers/musters/musters.js new file mode 100644 index 00000000..15426c35 --- /dev/null +++ b/app/controllers/musters/musters.js @@ -0,0 +1,42 @@ +'use strict'; + +const Queries = require('../../helpers/queries'); +const MustersParser = require('../../helpers/musters_parser'); +const Translate = require('../../templates/helpers/t'); + +exports.showPage = { + handler: function(request, reply) { + return reply.view('musters/musters'); + } +}; + +exports.getData = { + handler: function(request, reply) { + var sequelize = request.server.plugins.sequelize.db.sequelize; + var userId = request.auth.credentials.id; + var role = request.auth.credentials.role; + var queryString = Queries.cards(userId, role); + + sequelize.query(queryString, { + type: sequelize.QueryTypes.SELECT + }).then(function(rows) { + var data; + if (role === 'block') { + data = MustersParser.block(rows); + data.config ={ + role: 'block' + }; + } else if (role === 'district') { + data = MustersParser.district(rows); + data.config ={ + role: 'district' + }; + } + + data.translation = Translate('/web/musters', request.auth.credentials, null); + + return reply(data); + + }); + } +}; diff --git a/app/controllers/overview/overview.js b/app/controllers/overview/overview.js new file mode 100644 index 00000000..d8c69a12 --- /dev/null +++ b/app/controllers/overview/overview.js @@ -0,0 +1,30 @@ +'use strict'; + +const Queries = require('../../helpers/queries'); +const OverviewParser = require('../../helpers/overview_parser'); +const Translate = require('../../templates/helpers/t'); + +exports.showPage = { + handler: function(request, reply) { + return reply.view('overview/overview'); + } +}; + +exports.getData = { + handler: function(request, reply) { + + var sequelize = request.server.plugins.sequelize.db.sequelize; + var role = request.auth.credentials.role; + var userId = request.auth.credentials.id; + var queryString = Queries.overview(userId, role); + + sequelize.query(queryString, { + type: sequelize.QueryTypes.SELECT + }).then(function(rows) { + + var data = OverviewParser.parser(rows); + data.translation = Translate('/web/overview', request.auth.credentials, null); + reply(data); + }); + } +}; diff --git a/app/controllers/performance/discrete.js b/app/controllers/performance/discrete.js deleted file mode 100644 index ba4be02d..00000000 --- a/app/controllers/performance/discrete.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -var Queries = require('../../helpers/queries'); -var DiscreteParser = require('../../helpers/discrete_parser'); - -exports.showPage = { - auth: { - strategy: 'standard' - }, - handler: function(request, reply) { - return reply.view('performance/discrete'); - } -}; - - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var region_code = request.query.region_code; - var role = request.auth.credentials.role; - var queryString = Queries.discretePerformance(region_code, role); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - - if (role === 'block') { - var final_dict = DiscreteParser.block(rows, role, request.auth.credentials); - } else if (role === 'district') { - var final_dict = DiscreteParser.district(rows, role, request.auth.credentials); - } - - reply(final_dict); - }); - - } -}; diff --git a/app/controllers/performance/overview.js b/app/controllers/performance/overview.js deleted file mode 100644 index bb42e3bd..00000000 --- a/app/controllers/performance/overview.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var Queries = require('../../helpers/queries'); -var OverviewParser = require('../../helpers/overview_parser'); -var Translate = require('../../templates/helpers/t'); - -exports.showPage = { - handler: function(request, reply) { - return reply.view('performance/overview'); - } -}; - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var region_code = request.query.region_code; - var role = request.auth.credentials.role; - var queryString = Queries.overviewPerformance(region_code, role); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - - var final_dict; - - if (role === 'block') { - final_dict = OverviewParser.block(rows); - } - - if (role === 'district') { - final_dict = OverviewParser.district(rows); - } - - final_dict.config = { - role: role, - headers: ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn'], - labels: Translate('/payment_steps_labels', request.auth.credentials), - y_axis_label : Translate('/y_axis_labels', request.auth.credentials), - compare_chart_labels: Translate('/compare_chart_labels', request.auth.credentials), - comparison_lines: role === 'block' ? ['block', 'district', 'state'] : ['district', 'state'] - }; - - reply(final_dict); - }); - } -}; diff --git a/app/controllers/performance/panchayat.js b/app/controllers/performance/panchayat.js deleted file mode 100644 index 062e0b4d..00000000 --- a/app/controllers/performance/panchayat.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -var Queries = require('../../helpers/queries'); -var Utils = require('../../helpers/utils'); -var Translate = require('../../templates/helpers/t'); - -exports.getData = { - handler: function(request, reply) { - - var sequelize = request.server.plugins.sequelize.db.sequelize; - var region_code = request.query.panchayat_code; - var queryString = Queries.panchayatPerformance(region_code); - - sequelize.query(queryString, { - type: sequelize.QueryTypes.SELECT - }).then(function(rows) { - - var final_dict = {}; - var regionResponse = Utils.flatten(rows[0]); - var panchayatResponse = Utils.flatten(rows[1]); - var panchayatName = regionResponse[0].region_name; - var panchayatCode = region_code; - final_dict.panchayat = { - 'panchayat_code': panchayatCode, - 'panchayat_name': panchayatName, - 'data': panchayatResponse.map(function(d) { - return [ - d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - - final_dict.config = { - 'headers': ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn'], - labels: Translate('/payment_steps_labels', request.auth.credentials), - y_axis_label: Translate('/y_axis_labels', request.auth.credentials), - sidebar: { - avg_days: Translate('/performance/discrete/sidebar/avg_days', credentials), - total_trans: Translate('/performance/discrete/sidebar/total_trans', credentials), - } - }; - reply(final_dict); - }); - - } -}; diff --git a/app/controllers/performance/performance.js b/app/controllers/performance/performance.js new file mode 100644 index 00000000..045297d1 --- /dev/null +++ b/app/controllers/performance/performance.js @@ -0,0 +1,43 @@ +'use strict'; + +const Queries = require('../../helpers/queries'); +const PerformanceParser = require('../../helpers/performance_parser'); +const Translate = require('../../templates/helpers/t'); + +exports.showPage = { + handler: function(request, reply) { + return reply.view('performance/performance'); + } +}; + +exports.getData = { + handler: function(request, reply) { + + var sequelize = request.server.plugins.sequelize.db.sequelize; + var userId = request.auth.credentials.id; + var role = request.auth.credentials.role; + var queryString = Queries.performance(userId, role); + + sequelize.query(queryString, { + type: sequelize.QueryTypes.SELECT + }).then(function(rows) { + + var data; + if (role === 'block') { + data = PerformanceParser.block(rows); + } else if (role === 'district') { + data = PerformanceParser.district(rows); + } + + data.config = { + role: role, + headers: ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn'], + comparison_lines: role === 'block' ? ['state','district'] : ['state'] + }; + + data.translation = Translate('/web/performance', request.auth.credentials, null); + + reply(data); + }); + } +}; diff --git a/app/controllers/users/settings-account.js b/app/controllers/users/settings-account.js index 1313235b..317b1779 100644 --- a/app/controllers/users/settings-account.js +++ b/app/controllers/users/settings-account.js @@ -1,7 +1,7 @@ 'use strict'; -var Joi = require('joi'); -var crypto = require('crypto'); +const Joi = require('joi'); +const Crypto = require('crypto'); exports.showEditAccount = { description: 'Show Edit account settings', @@ -28,14 +28,14 @@ exports.postChangePassword = { }, failAction: function(request, reply, source, error) { // Boom bad request - request.session.flash('error', 'Bad request'); + request.yar.flash('error', 'Bad request'); return reply.redirect('/signin'); } }, handler: function(request, reply) { if (request.payload.newPassword !== request.payload.verify) { - request.session.flash('error', ' New Password does not match'); + request.yar.flash('error', ' New Password does not match'); return reply.redirect('/me/settings/account'); } var User = request.server.plugins.sequelize.db.User; @@ -43,20 +43,20 @@ exports.postChangePassword = { User.findOne({ where: { username: request.auth.credentials.username, - password: crypto.createHash('md5').update(request.payload.oldPassword).digest('hex') + password: Crypto.createHash('md5').update(request.payload.oldPassword).digest('hex') } }).then(function(user) { if (user) { user.update({ - password: crypto.createHash('md5').update(request.payload.newPassword).digest('hex') + password: Crypto.createHash('md5').update(request.payload.newPassword).digest('hex') }).then(function() { - request.session.flash('success', 'Password changed successfully. Please login with new password'); - request.auth.session.clear(); + request.yar.flash('success', 'Password changed successfully. Please login with new password'); + request.cookieAuth.clear(); return reply.redirect('/login'); }); } else { // User not fond in database - request.session.flash('error', 'Old password is incorrect'); + request.yar.flash('error', 'Old password is incorrect'); return reply.redirect('/me/settings/account'); } }); diff --git a/app/controllers/users/settings-profile.js b/app/controllers/users/settings-profile.js index 028ad3eb..506c02c5 100644 --- a/app/controllers/users/settings-profile.js +++ b/app/controllers/users/settings-profile.js @@ -1,6 +1,6 @@ 'use strict'; -var Joi = require('joi'); +const Joi = require('joi'); exports.showEditProfile = { description: 'Show Edit profile settings', @@ -20,12 +20,12 @@ exports.postEditProfile = { mobile: Joi.string().max(100).allow(''), email: Joi.string().max(100).allow(''), work_email: Joi.string().max(100).allow(''), - lang: Joi.string().max(100) + lang: Joi.string().max(100), + colorblind: Joi.string().max(100) }, failAction: function(request, reply, source, error) { // Boom bad request - console.log(error); - request.session.flash('error', 'Bad request'); + request.yar.flash('error', 'Bad request'); return reply.redirect('/me/settings/profile'); } }, @@ -43,15 +43,15 @@ exports.postEditProfile = { }).then(function(user) { if (user) { // if the record exists in the db user.update(request.payload).then(function() { - request.auth.session.clear(); - request.auth.session.set(user); - request.session.flash('success', 'Profile successfully saved'); + request.cookieAuth.clear(); + request.cookieAuth.set(user); + request.yar.flash('success', 'Profile successfully saved'); return reply.redirect('/me/settings/profile'); }); } else { - request.session.flash('error', 'An internal server error occurred'); + request.yar.flash('error', 'An internal server error occurred'); return reply.redirect('/me/settings/profile'); } }); diff --git a/app/helpers/discrete_parser.js b/app/helpers/discrete_parser.js deleted file mode 100644 index 64ce3c48..00000000 --- a/app/helpers/discrete_parser.js +++ /dev/null @@ -1,199 +0,0 @@ -'use strict'; - -var Utils = require('./utils'); -var D3 = require('d3'); -var Translate = require('../templates/helpers/t'); - -exports.block = function(rows, role, credentials) { - var final_dict = {}; - var regionName = rows[0][0].region_name; - - final_dict.region_name = regionName; - - var childrenResponse = Utils.flatten(rows[1]); - - var employeeResponse = Utils.flatten(rows[2]); - - var empMapping = { - 'TA': Utils.nestEmpMapping(rows[3]), - 'GRS': Utils.nestEmpMapping(rows[4]) - }; - - var employeeStats = { - 'past30': { - 'TA': Utils.nestEmpStats(rows[5]), - 'GRS': Utils.nestEmpStats(rows[6]) - }, - 'past60': { - 'TA': Utils.nestEmpStats(rows[7]), - 'GRS': Utils.nestEmpStats(rows[8]) - }, - 'all': { - 'TA': Utils.nestEmpStats(rows[9]), - 'GRS': Utils.nestEmpStats(rows[10]) - } - }; - - var mappingResponse = Utils.flatten(rows[11]); - - // process children data - final_dict.discrete = D3.nest() - .key(function(d) { - return d.region_code; - }) - .rollup(function(v) { - return { - 'region_code': v[0].region_code, - 'region_name': v[0].region_name, - 'mapped_ta': empMapping.TA[v[0].region_code], - 'mapped_grs': empMapping.GRS[v[0].region_code], - 'data': v.map(function(d) { - return [ - d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - }) - .entries(childrenResponse) - .map(function(d) { - return d.values; - }) - .sort(function(a, b) { - var aTarget = a.data[a.data.length - 1]; - var bTarget = b.data[b.data.length - 1]; - var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; - var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; - return bSum - aSum; - }); - - // process employee data - final_dict.employees = D3.nest() - .key(function(d) { - return d.task_assign; - }) - .rollup(function(v) { - return D3.nest() - .key(function(d) { - return d.staff_id; - }) - .rollup(function(w) { - return { - 'staff_id': w[0].staff_id, - 'name': w[0].name, - 'mobile': w[0].mobile_no, - 'step1_avg_30': employeeStats.past30[w[0].task_assign][w[0].staff_id].step1_avg, - 'tot_trans_30': employeeStats.past30[w[0].task_assign][w[0].staff_id].total_transactions || 0, - 'step1_avg_60': employeeStats.past60[w[0].task_assign][w[0].staff_id].step1_avg, - 'tot_trans_60': employeeStats.past60[w[0].task_assign][w[0].staff_id].total_transactions || 0, - 'step1_avg_all': employeeStats.all[w[0].task_assign][w[0].staff_id].step1_avg, - 'tot_trans_all': employeeStats.all[w[0].task_assign][w[0].staff_id].total_transactions || 0, - 'panchayats': w.map(function(d) { - return { - 'region_code': d.map_location, - 'region_name': d.mapped_panchayat_name - }; - }) - }; - }) - .entries(v) - .map(function(d) { - return d.values; - }); - - }) - .map(employeeResponse); - - final_dict.mapping = { - 'total_panchayat_count': mappingResponse[0].total_panchayat_count, - 'grs_panchayat_count': mappingResponse[0].grs_panchayat_count, - 'ta_panchayat_count': mappingResponse[0].ta_panchayat_count - }; - - final_dict.config = { - 'headers': ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn'], - 'role': role, - 'labels': Translate('/payment_steps_labels', credentials), - 'y_axis_labels': Translate('/y_axis_labels', credentials), - 'sidebar': { - avg_days: Translate('/performance/discrete/sidebar/avg_days', credentials), - total_trans: Translate('/performance/discrete/sidebar/total_trans', credentials), - } - }; - - return final_dict; -} - -exports.district = function(rows, role, credentials) { - - var final_dict = {}; - var regionName = rows[0][0].region_name; - - final_dict.region_name = regionName; - - var blockResponse = Utils.flatten(rows[1]); - var panchayatResponse = Utils.flatten(rows[2]); - - // process children data - final_dict.discrete = D3.nest() - .key(function(d) { - return d.region_code; - }) - .rollup(function(v) { - return { - 'block_code': v[0].region_code, - 'block_name': v[0].region_name, - 'data': v.map(function(d) { - return [ - d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }), - 'panchayats': panchayatResponse.filter(function(d) { - return d.block_code === v[0].region_code; - }).map(function(d) { - return { - 'panchayat_code': d.panchayat_code, - 'panchayat_name': d.panchayat_name - }; - }) - }; - }) - .entries(blockResponse) - .map(function(d) { - return d.values; - }) - .sort(function(a, b) { - var aTarget = a.data[a.data.length - 1]; - var bTarget = b.data[b.data.length - 1]; - var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; - var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; - return bSum - aSum; - }); - - final_dict.config = { - 'headers': ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn'], - 'role': role, - 'labels': Translate('/payment_steps_labels', credentials), - 'y_axis_label': Translate('/y_axis_labels', credentials), - 'sidebar': { - avg_days: Translate('/performance/discrete/sidebar/avg_days', credentials), - total_trans: Translate('/performance/discrete/sidebar/total_trans', credentials), - } - }; - return final_dict; -} diff --git a/app/helpers/musters_parser.js b/app/helpers/musters_parser.js new file mode 100644 index 00000000..33f72f8d --- /dev/null +++ b/app/helpers/musters_parser.js @@ -0,0 +1,153 @@ +'use strict'; + +const Utils = require('./utils'); +const D3 = require('d3'); + +exports.block = function(rows) { + + var cardsResponse = D3.values(rows[0]); + var stateResponse = D3.values(rows[1]); + var stateCode = stateResponse[0].state_code; + + // Nest the cards response + var cards = D3.nest() + .key(function(d) { + return d.block_code + d.block_name; + }) + .key(function(d) { + return d.staff_id; + }) + .rollup(function(v) { + return { + 'name': v[0].name, + 'designation': Utils.getDesignation(v[0].task_assign, stateCode), + 'mobile': v[0].mobile_no, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'delayed_musters': v.filter(function(d) { + return d.type === 'delayed_musters'; + }).map(function(d) { + return { + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date, + 'days_pending': d.days_pending + }; + }), + 'current_musters': v.filter(function(d) { + return d.type === 'current_musters'; + }).map(function(d) { + return { + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date + }; + }) + }; + }) + .entries(cardsResponse) + .map(function(d) { + return { + 'region_type': 'block', + 'region_code': d.key.substr(0,7), + 'region_name': d.key.substr(7), + 'cards': d.values.map(function(e) { + return e.values; + }).sort(function (a, b){ + var aActive = a.current_total + a.delayed_total > 0 ? 1 : 0; + var bActive = b.current_total + b.delayed_total > 0 ? 1 : 0; + var aUnmapped = a.name === 'Unmapped' ? 1 : 0; + var bUnmapped = b.name === 'Unmapped' ? 1 : 0; + + // ORDER BY active DESC, unmapped, delayed_total DESC, current_total DESC, name;" + + if (aActive < bActive) return 1; + if (aActive > bActive) return -1; + if (aUnmapped < bUnmapped) return -1; + if (aUnmapped > bUnmapped) return 1; + if (a.delayed_total < b.delayed_total) return 1; + if (a.delayed_total > b.delayed_total) return -1; + if (a.current_total < b.current_total) return 1; + if (a.current_total > b.current_total) return -1; + if (a.name.toLowerCase() < b.name.toLowerCase()) return -1; + if (a.name.toLowerCase() > b.name.toLowerCase()) return 1; + return 0; + }) + }; + }); + + var data = { + 'musters': cards + }; + + return data; +}; + +exports.district = function(rows) { + + var cardsResponse = rows; + + // Nest the cards response + var cards = D3.nest() + .key(function(d) { + return d.district_code + d.district_name; + }) + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'officers': v.map(function(d) { + return { + officer_id: d.block_code + '_' + d.designation_id, + name: d.firstname == null && d.lastname == null ? 'No Data' : d.firstname.toUpperCase() + ' ' + d.lastname.toUpperCase(), + designation: d.designation, + designation_id: d.designation_id, + mobile: d.mobile + }; + }).sort(function(a,b) { + return a.designation_id - b.designation_id; + }), + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'days_to_payment': v[0].days_to_payment, + 't2_total': v[0].t2_total, + 't2_avg': v[0].t2_avg, + 't5_total': v[0].t5_total, + 't5_avg': v[0].t5_avg, + 't6_total': v[0].t6_total, + 't6_avg': v[0].t6_avg, + 't7_total': v[0].t7_total, + 't7_avg': v[0].t7_avg, + 't8_total': v[0].t8_total, + 't8_avg': v[0].t8_avgw + }; + }) + .entries(cardsResponse) + .map(function(d) { + return { + 'region_type': 'district', + 'region_code': d.key.substr(0,4), + 'region_name': d.key.substr(4), + 'cards': d.values.map(function(e) { + return e.values; + }).sort(function (a, b){ + if (a.block_name.toLowerCase() < b.block_name.toLowerCase()) return -1; + if (a.block_name.toLowerCase() > b.block_name.toLowerCase()) return 1; + return 0; + }) + }; + }); + + var data = { + 'musters': cards + }; + + return data; +}; diff --git a/app/helpers/notifier.js b/app/helpers/notifier.js deleted file mode 100644 index 54f402ba..00000000 --- a/app/helpers/notifier.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -var Translate = require('../templates/helpers/t'); - - -exports.message = function(n, request) { - var msg = ''; - - if (n.dataValues.notification_type === 1) { - var region_name = n.dataValues.region_name; - var total_transactions = n.dataValues.total_transactions; - var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - var batch_date = n.dataValues.batch_date.getDate() + ' ' + monthNames[n.dataValues.batch_date.getMonth()] + ' ' + n.dataValues.batch_date.getFullYear(); - var notification_sub_text = Translate('/notifications/message/1', request.auth.credentials); - - if (request.auth.credentials.lang === 'en_US') { - msg = region_name + notification_sub_text[0] + total_transactions + notification_sub_text[1] + batch_date + notification_sub_text[2]; - } else if (request.auth.credentials.lang === 'hi') { - msg = region_name + notification_sub_text[0] + batch_date + notification_sub_text[1] + total_transactions + notification_sub_text[2]; - } - - } - - if (n.dataValues.notification_type === 2) { - var days_to_payment = n.dataValues.days_to_payment; - var notification_sub_text = Translate('/notifications/message/2/main', request.auth.credentials); - var comparison_array = Translate('/notifications/message/2/comparison', request.auth.credentials); - - if (days_to_payment > 15) { - var comparison_text = comparison_array[0]; - } else if (days_to_payment === 15) { - var comparison_text = comparison_array[1]; - } else if (days_to_payment < 15) { - var comparison_text = comparison_array[2]; - } - - msg = notification_sub_text[0] + days_to_payment + notification_sub_text[1] + comparison_text + notification_sub_text[2]; - - } - - return msg; -} diff --git a/app/helpers/overview_parser.js b/app/helpers/overview_parser.js index efe98dda..ec5509b5 100644 --- a/app/helpers/overview_parser.js +++ b/app/helpers/overview_parser.js @@ -1,177 +1,34 @@ 'use strict'; -var Utils = require('./utils'); +const D3 = require('d3'); -var final_dict = {}; +exports.parser = function(rows) { -final_dict.monthwise = {}; -final_dict.datewise = {}; + var overviewResponse = rows; -exports.block = function(rows) { - - // Process state data - var stateResponse = Utils.flatten(rows[0]); - var stateName = stateResponse[0].state_name; - var stateCode = stateResponse[0].state_code; - - final_dict.monthwise.state = { - 'state_code': stateCode, - 'state_name': stateName, - 'data': stateResponse.map(function(d) { - return [ - d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - - // Process district data - var districtResponse = Utils.flatten(rows[1]); - var districtName = districtResponse[0].district_name; - var districtCode = districtResponse[0].district_code; - final_dict.monthwise.district = { - 'district_code': districtCode, - 'district_name': districtName, - 'data': districtResponse.map(function(d) { - return [ - d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; + var overview = D3.nest() + .key(function(d) { + return d.region_code; }) - }; - - // Process block data for bottom chart (grouped by month) - var blockResponse = Utils.flatten(rows[2]); - var blockName = blockResponse[0].block_name; - var blockCode = blockResponse[0].block_code; - final_dict.monthwise.block = { - 'block_code': blockCode, - 'block_name': blockName, - 'data': blockResponse.map(function(d) { - return [ - d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; - - // Process block data for top chart (group by date) - var blockResponse = Utils.flatten(rows[3]); - var blockName = blockResponse[0].block_name; - var blockCode = blockResponse[0].block_code; - final_dict.datewise.block = { - 'block_code': blockCode, - 'block_name': blockName, - 'data': blockResponse.map(function(d) { - return [ - d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; + .rollup(function(v) { + return { + 'region_code': v[0].region_code, + 'region_name': v[0].region_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'days_to_payment': v[0].days_to_payment + }; }) - }; - - final_dict.region_name = blockName; - return final_dict; -} - -exports.district = function(rows) { - - - // process state data - var stateResponse = Utils.flatten(rows[0]); - var stateName = stateResponse[0].state_name; - var stateCode = stateResponse[0].state_code; + .entries(overviewResponse) + .map(function(d) { + return d.values; + }); - final_dict.monthwise.state = { - 'state_code': stateCode, - 'state_name': stateName, - 'data': stateResponse.map(function(d) { - return [ - d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) + var data = { + 'overview': overview }; - // Process district data for bottom chart (monthwise data) - var districtResponse = Utils.flatten(rows[1]); - var districtName = districtResponse[0].district_name; - var districtCode = districtResponse[0].district_code; - final_dict.monthwise.district = { - 'district_code': districtCode, - 'district_name': districtName, - 'data': districtResponse.map(function(d) { - return [ - d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; + return data; - // Process district data for top chart (datewise data) - var districtResponse = Utils.flatten(rows[2]); - var districtName = districtResponse[0].district_name; - var districtCode = districtResponse[0].district_code; - final_dict.datewise.district = { - 'district_code': districtCode, - 'district_name': districtName, - 'data': districtResponse.map(function(d) { - return [ - d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), - d.mrc_mre, - d.mre_wlg, - d.wlg_wls, - d.wls_fto, - d.fto_sn1, - d.sn1_sn2, - d.sn2_prc, - d.tot_trn - ]; - }) - }; +}; - final_dict.region_name = districtName; - return final_dict; -} diff --git a/app/helpers/paydroid_parser.js b/app/helpers/paydroid_parser.js new file mode 100644 index 00000000..c03d0241 --- /dev/null +++ b/app/helpers/paydroid_parser.js @@ -0,0 +1,634 @@ +'use strict'; + +const D3 = require('d3'); +const Utils = require('./utils'); + +exports.v1 = function(rows) { + + var overviewResponse = D3.values(rows[0]); + + var cardsResponse = D3.values(rows[1]); + + var blockResponse = D3.values(rows[2]); + + var panchayatResponse = D3.values(rows[3]); + + var notificationsResponse = D3.values(rows[4]); + + var stateResponse = D3.values(rows[5]); + + var contactResponse = D3.values(rows[6]); + + // Parse the overview response + var current_total = overviewResponse[0].current_total; + var delayed_total = overviewResponse[0].delayed_total; + var days_to_payment = overviewResponse[0].days_to_payment; + var total_transactions = overviewResponse[0].total_transactions; + + var state_code = stateResponse[0].state_code; + + // Nest the cards response and include the overview stats + var cards = D3.nest() + .key(function(d) { + return d.staff_id; + }) + .rollup(function(v) { + return { + 'name': v[0].name, + 'staff_id': v[0].staff_id, + 'designation': Utils.getDesignation(v[0].task_assign, state_code), + 'mobile': v[0].mobile_no, + 'block_name': v[0].block_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'delayed_musters': v.filter(function(d) { + return d.type === 'delayed_musters'; + }).map(function(d) { + return [{ + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date, + 'days_pending': d.days_pending + }]; + }), + 'current_musters': v.filter(function(d) { + return d.type === 'current_musters'; + }).map(function(d) { + return [{ + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date + }]; + }) + }; + }) + .entries(cardsResponse) + .map(function(d) { + return d.values; + }); + + // Nest the block response + var blockPerformance = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'data': v.map(function(d) { + return [ + d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(blockResponse) + .map(function(d) { + return d.values; + }) + .sort(function(a, b) { + var aTarget = a.data[a.data.length - 1]; + var bTarget = b.data[b.data.length - 1]; + var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; + var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; + return bSum - aSum; + }); + + + // Nest the panchayat response + var panchayatPerformance = D3.nest() + .key(function(d) { + return d.panchayat_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'panchayat_code': v[0].panchayat_code, + 'panchayat_name': v[0].panchayat_name, + 'data': v.map(function(d) { + return [ + d.date.getFullYear() + '' + Utils.padNum(d.date.getMonth() + 1) + '' + Utils.padNum(d.date.getDate()), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(panchayatResponse) + .map(function(d) { + return d.values; + }) + .sort(function(a, b) { + var aTarget = a.data[a.data.length - 1]; + var bTarget = b.data[b.data.length - 1]; + var aSum = aTarget[1] + aTarget[2] + aTarget[3] + aTarget[4] + aTarget[5] + aTarget[6] + aTarget[7]; + var bSum = bTarget[1] + bTarget[2] + bTarget[3] + bTarget[4] + bTarget[5] + bTarget[6] + bTarget[7]; + return bSum - aSum; + }); + + var headers = ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'tot_trn']; + + var data = { + 'overview': { + 'current_total': current_total, + 'delayed_total': delayed_total, + 'days_to_payment': days_to_payment, + 'total_transactions': total_transactions, + 'cards_total': cards.length + }, + 'cards': cards, + 'block_performance': blockPerformance, + 'panchayat_performance': panchayatPerformance, + 'notifications': notificationsResponse, + 'config': { + 'headers': headers, + labels: [ + 'Date', + 'Muster roll closure to muster roll entry', + 'Muster roll entry to wage list generation', + 'Wage list generation to wage list sent', + 'Wage list sent to FTO generation', + 'FTO generation to first signature', + 'First signature to second signature', + 'Second signature to processed by bank', + 'Total Transactions' + ], + }, + 'contact': { + 'phone': contactResponse[0].phone, + 'email': contactResponse[0].email, + 'subject': contactResponse[0].subject + } + }; + + return data; + +}; + + +exports.v2 = function(rows, role) { + + function parse_block(rows) { + + var overviewResponse = D3.values(rows[0]); + + var cardsResponse = D3.values(rows[1]); + + var blockResponse = D3.values(rows[2]); + + var panchayatResponse = D3.values(rows[3]); + + var stateResponse = D3.values(rows[4]); + + var contactResponse = D3.values(rows[5]); + + var versionResponse = D3.values(rows[6]); + + var regionsResponse = D3.values(rows[7]); + + // Parse the overview response + var overview = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'days_to_payment': v[0].days_to_payment + } + }) + .entries(overviewResponse) + .map(function(d) { + return d.values; + }); + + var state_code = stateResponse[0].state_code; + + // Nest the cards response and include the overview stats + var cards = D3.nest() + .key(function(d) { + var key = d.staff_id + d.block_code; + return key; + }) + .rollup(function(v) { + return { + 'name': v[0].name, + 'staff_id': v[0].staff_id, + 'designation': Utils.getDesignation(v[0].task_assign, state_code), + 'mobile': v[0].mobile_no, + 'block_name': v[0].block_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'delayed_musters': v.filter(function(d) { + return d.type === 'delayed_musters'; + }).map(function(d) { + return { + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date, + 'days_pending': d.days_pending, + 'step': d.step + }; + }), + 'current_musters': v.filter(function(d) { + return d.type === 'current_musters'; + }).map(function(d) { + return { + 'msr_no': d.msr_no, + 'panchayat_name': d.panchayat_name, + 'work_name': d.work_name, + 'work_code': d.work_code, + 'closure_date': d.end_date + }; + }) + }; + }) + .entries(cardsResponse) + .map(function(d) { + return d.values; + }) + .sort(function (a, b){ + var aActive = a.current_total + a.delayed_total > 0 ? 1 : 0; + var bActive = b.current_total + b.delayed_total > 0 ? 1 : 0; + var aUnmapped = a.name.toLowerCase() === 'unmapped' ? 1 : 0; + var bUnmapped = b.name.toLowerCase() === 'unmapped' ? 1 : 0; + + // ORDER BY active DESC, unmapped, delayed_total DESC, current_total DESC, name;" + + if (aActive < bActive) return 1; + if (aActive > bActive) return -1; + if (aUnmapped < bUnmapped) return -1; + if (aUnmapped > bUnmapped) return 1; + if (a.delayed_total < b.delayed_total) return 1; + if (a.delayed_total > b.delayed_total) return -1; + if (a.current_total < b.current_total) return 1; + if (a.current_total > b.current_total) return -1; + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; + return 0; + }); + + + // Nest the block response + var blockPerformance = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.mrc_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(blockResponse) + .map(function(d) { + return d.values; + }); + + + // Nest the panchayat response + var panchayatPerformance = D3.nest() + .key(function(d) { + return d.panchayat_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'panchayat_code': v[0].panchayat_code, + 'panchayat_name': v[0].panchayat_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.mrc_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(panchayatResponse) + .map(function(d) { + return d.values; + }); + + var headers = ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'mrc_prc','tot_trn']; + + var subjectLine = Utils.buildSubject(contactResponse[0].subject, regionsResponse); + + var data = { + 'overview': overview, + 'cards': cards, + 'block_performance': blockPerformance, + 'panchayat_performance': panchayatPerformance, + 'config': { + 'headers': headers, + labels: [ + 'Date', + 'Muster roll closure to muster roll entry', + 'Muster roll entry to wage list generation', + 'Wage list generation to wage list sent', + 'Wage list sent to FTO generation', + 'FTO generation to first signature', + 'First signature to second signature', + 'Second signature to processed by bank', + 'Total Length of Process', + 'Total Transactions' + ], + }, + 'contact': { + 'phone': contactResponse[0].phone, + 'email': contactResponse[0].email, + 'subject': subjectLine + }, + 'colors': { + 'default': [ + '#F15854', + '#B2912F', + '#F17CB0', + '#60BD68', + '#FAA43A', + '#5DA5DA', + '#B276B2', + '#97D19C' + ], + 'colorblind': [ + '#E69F00', + '#56B4E9', + '#009E73', + '#000000', + '#F0E442', + '#D55E00', + '#CC79A7', + '#0072b2' + ] + }, + 'version': versionResponse[0].version + }; + + return data; + } + + function parse_district(rows) { + + var overviewResponse = D3.values(rows[0]); + + var cardsResponse = D3.values(rows[1]); + + var districtResponse = D3.values(rows[2]); + + var blockResponse = D3.values(rows[3]); + + var stateResponse = D3.values(rows[4]); + + var contactResponse = D3.values(rows[5]); + + var versionResponse = D3.values(rows[6]); + + var regionsResponse = D3.values(rows[7]); + + // Parse the overview response + var overview = D3.nest() + .key(function(d) { + return d.district_code; + }) + .rollup(function(v) { + return { + 'district_code': v[0].district_code, + 'district_name': v[0].district_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'days_to_payment': v[0].days_to_payment + } + }) + .entries(overviewResponse) + .map(function(d) { + return d.values; + }); + + var state_code = stateResponse[0].state_code; + + // Nest the cards response and include the overview stats + var cards = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'officers': v.map(function(d) { + return { + officer_id: d.block_code + '_' + d.designation_id, + name: d.firstname == null && d.lastname == null ? 'No Data' : d.firstname.toUpperCase() + ' ' + d.lastname.toUpperCase(), + designation: d.designation, + designation_id: d.designation_id, + mobile: d.mobile + }; + }).sort(function(a,b) { + return a.designation_id - b.designation_id; + }), + 'district_name': v[0].district_name, + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'current_total': v[0].current_total, + 'delayed_total': v[0].delayed_total, + 'days_to_payment': v[0].days_to_payment, + 't2_total': v[0].t2_total, + 't2_avg': v[0].t2_avg, + 't5_total': v[0].t5_total, + 't5_avg': v[0].t5_avg, + 't6_total': v[0].t6_total, + 't6_avg': v[0].t6_avg, + 't7_total': v[0].t7_total, + 't7_avg': v[0].t7_avg, + 't8_total': v[0].t8_total, + 't8_avg': v[0].t8_avg + }; + }) + .entries(cardsResponse) + .map(function(d) { + return d.values; + }) + .sort(function (a, b){ + if (a.district_name.toLowerCase() < b.district_name.toLowerCase()) return -1; + if (a.district_name.toLowerCase() > b.district_name.toLowerCase()) return 1; + if (a.block_name.toLowerCase() < b.block_name.toLowerCase()) return -1; + if (a.block_name.toLowerCase() > b.block_name.toLowerCase()) return 1; + return 0; + }); + + // Nest the district response + var districtPerformance = D3.nest() + .key(function(d) { + return d.district_code; + }) + .rollup(function(v) { + return { + 'district_code': v[0].district_code, + 'district_name': v[0].district_name, + 'block_code': v[0].block_code, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.mrc_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(districtResponse) + .map(function(d) { + return d.values; + }); + + + // Nest the block response + var blockPerformance = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.mrc_mre, + d.tot_trn + ]; + }) + }; + }) + .entries(blockResponse) + .map(function(d) { + return d.values; + }); + + + var subjectLine = Utils.buildSubject(contactResponse[0].subject, regionsResponse); + + var headers = ['date', 'mrc_mre', 'mre_wlg', 'wlg_wls', 'wls_fto', 'fto_sn1', 'sn1_sn2', 'sn2_prc', 'mrc_prc','tot_trn']; + + var data = { + 'overview': overview, + 'cards': cards, + 'district_performance': districtPerformance, + 'block_performance': blockPerformance, + 'config': { + 'headers': headers, + labels: [ + 'Date', + 'Muster roll closure to muster roll entry', + 'Muster roll entry to wage list generation', + 'Wage list generation to wage list sent', + 'Wage list sent to FTO generation', + 'FTO generation to first signature', + 'First signature to second signature', + 'Second signature to processed by bank', + 'Total Length of Process', + 'Total Transactions' + ], + }, + 'contact': { + 'phone': contactResponse[0].phone, + 'email': contactResponse[0].email, + 'subject': subjectLine + }, + 'colors': { + 'default': [ + '#F15854', + '#B2912F', + '#F17CB0', + '#60BD68', + '#FAA43A', + '#5DA5DA', + '#B276B2', + '#97D19C' + ], + 'colorblind': [ + '#E69F00', + '#56B4E9', + '#009E73', + '#000000', + '#F0E442', + '#D55E00', + '#CC79A7', + '#0072b2' + ] + }, + 'version': versionResponse[0].version + }; + + return data; + } + + if (role==='block') { + + var data = parse_block(rows); + + } else if (role==='district') { + + var data = parse_district(rows); + + } + + return data; + +}; diff --git a/app/helpers/performance_parser.js b/app/helpers/performance_parser.js new file mode 100644 index 00000000..ed3b73e4 --- /dev/null +++ b/app/helpers/performance_parser.js @@ -0,0 +1,249 @@ +'use strict'; + +const Utils = require('./utils'); +const D3 = require('d3'); + +exports.block = function(rows) { + + // Process state data + var stateResponse = D3.values(rows[0]); + var stateName = stateResponse[0].state_name; + var stateCode = stateResponse[0].state_code; + + var statePerformance = { + 'state_code': stateCode, + 'state_name': stateName, + 'data': stateResponse.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + + // Process district data (can only be 1 district per block official) + var districtResponse = D3.values(rows[1]); + var districtName = districtResponse[0].district_name; + var districtCode = districtResponse[0].district_code; + var districtPerformance = { + 'district_code': districtCode, + 'district_name': districtName, + 'data': districtResponse.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + + // Process block data for bottom chart (grouped by month) + var blockResponse = D3.values(rows[2]); + var blockName = blockResponse[0].block_name; + var blockCode = blockResponse[0].block_code; + + // Nest the block response (may be multiple blocks) + var blockPerformance = D3.nest() + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(blockResponse) + .map(function(d) { + return d.values; + }); + + + // Process list of panchayat names and codes + var panchayatResponse = D3.values(rows[3]); + + // Nest the panchayat response + var panchayatPerformance = D3.nest() + .key(function(d) { + return d.block_code + d.block_name; + }) + .key(function(d) { + return d.panchayat_code; + }) + .rollup(function(v) { + return { + 'panchayat_code': v[0].panchayat_code, + 'panchayat_name': v[0].panchayat_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(panchayatResponse) + .map(function(d) { + return { + 'block_code': d.key.substr(0, 7), + 'block_name': d.key.substr(7), + 'data': d.values.map(function(e) { + return e.values; + }) + }; + }); + + var data = { + performance: { + 'state': statePerformance, + 'district': districtPerformance, + 'block': blockPerformance, + 'panchayat': panchayatPerformance + } + }; + + return data; +}; + +exports.district = function(rows) { + + // Process state data + var stateResponse = D3.values(rows[0]); + var stateName = stateResponse[0].state_name; + var stateCode = stateResponse[0].state_code; + + var statePerformance = { + 'state_code': stateCode, + 'state_name': stateName, + 'data': stateResponse.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + + // Process district data for bottom chart (grouped by month) + var districtResponse = D3.values(rows[1]); + + // Nest the block response (may be multiple blocks) + var districtPerformance = D3.nest() + .key(function(d) { + return d.district_code; + }) + .rollup(function(v) { + return { + 'district_code': v[0].district_code, + 'district_name': v[0].district_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(districtResponse) + .map(function(d) { + return d.values; + }); + + + // Process list of block names and codes + var blockResponse = D3.values(rows[2]); + + // Nest the block response + var blockPerformance = D3.nest() + .key(function(d) { + return d.district_code + d.district_name; + }) + .key(function(d) { + return d.block_code; + }) + .rollup(function(v) { + return { + 'block_code': v[0].block_code, + 'block_name': v[0].block_name, + 'data': v.map(function(d) { + return [ + d.year + '' + Utils.padNum(d.month) + '' + Utils.padNum(1), + d.mrc_mre, + d.mre_wlg, + d.wlg_wls, + d.wls_fto, + d.fto_sn1, + d.sn1_sn2, + d.sn2_prc, + d.tot_trn + ]; + }) + }; + }) + .entries(blockResponse) + .map(function(d) { + return { + 'district_code': d.key.substr(0, 4), + 'district_name': d.key.substr(4), + 'data': d.values.map(function(e) { + return e.values; + }) + }; + }); + + var data = { + performance: { + 'state': statePerformance, + 'district': districtPerformance, + 'block': blockPerformance + } + }; + + return data; +}; diff --git a/app/helpers/queries.js b/app/helpers/queries.js index 16167b4d..90ff643c 100644 --- a/app/helpers/queries.js +++ b/app/helpers/queries.js @@ -1,48 +1,70 @@ 'use strict'; -exports.overviewPerformance = function(REGION_CODE, ROLE) { +exports.overview = function(USER_ID, ROLE) { if (ROLE === 'block') { - return "SELECT state_code,state_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM state_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.state_code in (SELECT b.state_code FROM blocks b WHERE b.block_code ='" + REGION_CODE + "') GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + - "SELECT district_code,district_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM district_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.district_code in (SELECT b.district_code FROM blocks b WHERE b.block_code ='" + REGION_CODE + "') GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + - "SELECT block_code,block_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code ='" + REGION_CODE + "' GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + - "SELECT block_code,block_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,0) mrc_mre,ROUND(mre_wlg_mean,0) mre_wlg,ROUND(wlg_wls_mean,0) wlg_wls,ROUND(wls_fto_mean,0) wls_fto,ROUND(fto_firstsign_mean,0) fto_sn1,ROUND(firstsign_secondsign_mean,0) sn1_sn2,ROUND(secondsign_processed_mean,0) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code ='" + REGION_CODE + "' ORDER BY date;"; + return "SELECT a.region_code, a.region_name, IFNULL(b.current_total,0) AS current_total, IFNULL(c.delayed_total,0) AS delayed_total, IFNULL(d.days_to_payment,'No Data') AS days_to_payment FROM (SELECT region_code, region_name FROM user_regions WHERE user_id='"+USER_ID+"') a LEFT JOIN (SELECT count(*) AS current_total, block_code AS region_code FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY region_code) b ON a.region_code = b.region_code LEFT JOIN (SELECT count(*) AS delayed_total, block_code AS region_code FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY region_code) c ON a.region_code = c.region_code LEFT JOIN (SELECT ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1) AS days_to_payment, block_code AS region_code FROM block_delays_duration WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY region_code) d ON a.region_code = d.region_code;"; } else if (ROLE === 'district') { - return "SELECT state_code,state_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM state_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.state_code in (SELECT b.state_code FROM districts b WHERE b.district_code ='" + REGION_CODE + "') GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + - "SELECT district_code,district_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM district_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.district_code='" + REGION_CODE + "' GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + - "SELECT district_code,district_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,0) mrc_mre,ROUND(mre_wlg_mean,0) mre_wlg,ROUND(wlg_wls_mean,0) wlg_wls,ROUND(wls_fto_mean,0) wls_fto,ROUND(fto_firstsign_mean,0) fto_sn1,ROUND(firstsign_secondsign_mean,0) sn1_sn2,ROUND(secondsign_processed_mean,0) sn2_prc FROM district_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code ='" + REGION_CODE + "' ORDER BY date;"; + return "SELECT a.region_code, a.region_name, IFNULL(b.current_total,0) AS current_total, IFNULL(c.delayed_total,0) AS delayed_total, IFNULL(d.days_to_payment,'No Data') AS days_to_payment FROM (SELECT region_code, region_name FROM user_regions WHERE user_id='"+USER_ID+"') a LEFT JOIN (SELECT count(*) AS current_total, b.district_code AS region_code FROM current_musters a INNER JOIN (SELECT district_code, block_code from blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code GROUP BY region_code ) b ON a.region_code = b.region_code LEFT JOIN (SELECT count(*) AS delayed_total, b.district_code AS region_code FROM delayed_musters a INNER JOIN (SELECT district_code, block_code from blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code GROUP BY region_code ) c ON a.region_code = c.region_code LEFT JOIN (SELECT ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1) AS days_to_payment, district_code AS region_code FROM district_delays_duration WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY region_code) d ON a.region_code = d.region_code;"; } - }; -exports.discretePerformance = function(REGION_CODE, ROLE) { +exports.cards = function(USER_ID, ROLE) { if (ROLE === 'block') { - return "SELECT block_name AS region_name FROM blocks WHERE block_code = '" + REGION_CODE + "';" + - "SELECT panchayat_code AS region_code,panchayat_name AS region_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,0) mrc_mre,ROUND(mre_wlg_mean,0) mre_wlg,ROUND(wlg_wls_mean,0) wlg_wls,ROUND(wls_fto_mean,0) wls_fto,ROUND(fto_firstsign_mean,0) fto_sn1,ROUND(firstsign_secondsign_mean,0) sn1_sn2,ROUND(secondsign_processed_mean,0) sn2_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND block_code ='" + REGION_CODE + "' ORDER BY panchayat_code, date;" + - "SELECT staff_id, name, task_assign, mobile_no, map_location, mapped_panchayat_name FROM employees WHERE task_assign IN ('TA','GRS') AND block_code = '" + REGION_CODE + "';" + - "SELECT a.panchayat_code AS region_code, b.task_assign FROM (SELECT DISTINCT panchayat_code FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date') a LEFT JOIN (SELECT map_location, task_assign FROM employees WHERE block_code = '" + REGION_CODE + "' AND task_assign = 'TA') b ON a.panchayat_code = b.map_location;" + - "SELECT a.panchayat_code AS region_code, b.task_assign FROM (SELECT DISTINCT panchayat_code FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date') a LEFT JOIN (SELECT map_location, task_assign FROM employees WHERE block_code = '" + REGION_CODE + "' AND task_assign = 'GRS') b ON a.panchayat_code = b.map_location;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0 AND date > sysdate()-30) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='TA' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0 AND date > sysdate()-30) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='GRS' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0 AND date > sysdate()-60) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='TA' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0 AND date > sysdate()-60) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='GRS' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='TA' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT b.staff_id AS staff_id, ROUND(SUM(a.mrc_mre_mean * a.total_transactions) / SUM(a.total_transactions),0) AS step1_avg, SUM(total_transactions) as total_transactions FROM (SELECT panchayat_code, mrc_mre_mean, total_transactions FROM panchayat_delays_duration WHERE block_code = '" + REGION_CODE + "' AND panchayat_code <> '0000000000' AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions>0) a RIGHT JOIN (SELECT staff_id, map_location FROM employees WHERE task_assign='GRS' AND block_code = '" + REGION_CODE + "') b ON a.panchayat_code = b.map_location GROUP BY staff_id;" + - "SELECT a.total_panchayat_count, b.ta_panchayat_count, c.grs_panchayat_count FROM (SELECT block_code, IFNULL(count(*),0) AS total_panchayat_count FROM panchayats WHERE block_code = '" + REGION_CODE + "') a LEFT JOIN (SELECT '" + REGION_CODE + "' AS block_code, IFNULL(count(*),0) AS ta_panchayat_count FROM employees WHERE task_assign = 'TA' AND block_code = '" + REGION_CODE + "') b ON a.block_code = b.block_code LEFT JOIN (SELECT '" + REGION_CODE + "' AS block_code, IFNULL(count(*),0) AS grs_panchayat_count FROM employees WHERE task_assign = 'GRS' AND block_code = '" + REGION_CODE + "') c ON a.block_code = c.block_code;"; + return "SELECT a.staff_id, IFNULL(a.name,'Unmapped') AS name, a.task_assign, IFNULL(a.mobile_no,'') AS mobile_no, a.block_code, a.block_name, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, b.msr_no, b.work_name, b.work_code, b.panchayat_name, b.end_date, b.days_pending, b.step, b.type FROM (SELECT staff_id, name, task_assign, mobile_no, block_code, block_name FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") UNION SELECT a.staff_id, a.name, a.task_assign, a.mobile_no, b.block_code, b.block_name FROM (SELECT NULL as staff_id, NULL as name, NULL as task_assign, NULL as mobile_no, 1 as merge) a RIGHT JOIN (SELECT region_code as block_code, region_name as block_name, 1 as merge FROM user_regions WHERE user_id="+USER_ID+") b ON a.merge = b.merge ) a LEFT JOIN (SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, NULL as days_pending, NULL AS step, 'current_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 2) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 5) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code ) b ON a.staff_id=b.staff_id OR (a.staff_id IS NULL AND b.staff_id IS NULL AND a.block_code=b.block_code) LEFT JOIN (SELECT count(*) AS current_total, a.staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) c ON a.staff_id=c.staff_id OR (a.staff_id IS NULL AND c.staff_id IS NULL AND a.block_code=c.block_code) LEFT JOIN (SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code UNION SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) d ON a.staff_id=d.staff_id OR (a.staff_id IS NULL AND d.staff_id IS NULL AND a.block_code=d.block_code) WHERE a.staff_id IS NOT NULL OR (a.staff_id IS NULL AND (c.current_total>0 OR d.delayed_total>0));" + + "SELECT DISTINCT state_code FROM blocks WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"');"; } else if (ROLE === 'district') { - return "SELECT district_name AS region_name FROM districts WHERE district_code = '" + REGION_CODE + "';" + - "SELECT block_code AS region_code,block_name AS region_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,0) mrc_mre,ROUND(mre_wlg_mean,0) mre_wlg,ROUND(wlg_wls_mean,0) wlg_wls,ROUND(wls_fto_mean,0) wls_fto,ROUND(fto_firstsign_mean,0) fto_sn1,ROUND(firstsign_secondsign_mean,0) sn1_sn2,ROUND(secondsign_processed_mean,0) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code ='" + REGION_CODE + "' ORDER BY block_code, date;" + - "SELECT block_code, panchayat_code, panchayat_name FROM panchayats WHERE district_code = '" + REGION_CODE + "';"; + return "SELECT a.district_code, a.district_name, a.block_code, a.block_name, j.firstname, j.lastname, IFNULL(j.designation,'No Data') AS designation, j.designation_id, IFNULL(j.mobile,'No Data') AS mobile, b.days_to_payment, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, IFNULL(e.t2_total,0) AS t2_total, IFNULL(e.t2_avg,'') AS t2_avg, IFNULL(f.t5_total,0) AS t5_total, IFNULL(f.t5_avg,'') AS t5_avg, IFNULL(g.t6_total,0) AS t6_total, IFNULL(g.t6_avg,'') AS t6_avg, IFNULL(h.t7_total,0) AS t7_total, IFNULL(h.t7_avg,'') AS t7_avg, IFNULL(i.t8_total,0) AS t8_total, IFNULL(i.t8_avg,'') AS t8_avg FROM (SELECT district_code, district_name, block_code, block_name FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a LEFT JOIN (SELECT block_code, IFNULL(ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1),'No Data') AS days_to_payment FROM block_delays_duration WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY block_code) b ON a.block_code=b.block_code LEFT JOIN (SELECT b.block_code, count(*) AS current_total FROM current_musters a RIGHT JOIN blocks b ON a.block_code=b.block_code AND b.district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") GROUP BY a.block_code) c ON a.block_code=c.block_code LEFT JOIN (SELECT b.block_code, count(*) AS delayed_total FROM delayed_musters a RIGHT JOIN blocks b ON a.block_code=b.block_code AND b.district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") GROUP BY a.block_code) d ON a.block_code=d.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t2_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 2),1) AS t2_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t2') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) e ON a.block_code=e.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t5_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 5),1) AS t5_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t5') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) f ON a.block_code=f.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t6_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 6),1) AS t6_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t6') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) g ON a.block_code=g.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t7_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 7),1) AS t7_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t7') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) h ON a.block_code=h.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t8_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 8),1) AS t8_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t8') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) i ON a.block_code=i.block_code LEFT JOIN (SELECT a.block_code, a.firstname, a.lastname, a.designation, a.designation_id, a.mobile FROM block_officers a RIGHT JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code) j ON a.block_code=j.block_code;"; } +}; +exports.performance = function(USER_ID, ROLE) { + if (ROLE === 'block') { + return "SELECT state_code,state_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM state_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.state_code IN (SELECT b.state_code FROM blocks b WHERE b.block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + + "SELECT district_code,district_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM district_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.district_code IN (SELECT b.district_code FROM blocks b WHERE b.block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + + "SELECT block_code, block_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), block_code ORDER BY block_code, date;" + + "SELECT block_code, block_name, panchayat_code, panchayat_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), panchayat_code ORDER BY panchayat_code, date;"; + } else if (ROLE === 'district') { + return "SELECT state_code,state_name,SUM(total_transactions) tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM state_delays_duration a WHERE a.gender = 'both' AND a.bank_type = 'all' AND a.date_type = 'processed_date' AND a.total_transactions > 0 AND a.state_code IN (SELECT b.state_code FROM districts b WHERE b.district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) GROUP BY YEAR(date), MONTH(date) ORDER BY date;" + + "SELECT district_code, district_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM district_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), district_code ORDER BY district_code, date;" + + "SELECT district_code, district_name, block_code, block_name, SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),0) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),0) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),0) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),0) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),0) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),0) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),0) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), block_code ORDER BY block_code, date;"; + } }; -exports.panchayatPerformance = function(REGION_CODE) { - return "SELECT panchayat_name as region_name from panchayats where panchayat_code=" + REGION_CODE + ";" + - "SELECT panchayat_code AS region_code,panchayat_name AS region_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,0) mrc_mre,ROUND(mre_wlg_mean,0) mre_wlg,ROUND(wlg_wls_mean,0) wlg_wls,ROUND(wls_fto_mean,0) wls_fto,ROUND(fto_firstsign_mean,0) fto_sn1,ROUND(firstsign_secondsign_mean,0) sn1_sn2,ROUND(secondsign_processed_mean,0) sn2_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND panchayat_code ='" + REGION_CODE + "' ORDER BY panchayat_code, date;"; +exports.contact = function(USER_ID) { + return "SELECT * FROM contact;" + + "SELECT * FROM user_regions WHERE user_id="+USER_ID+";"; }; -exports.userBlocks = function(USER_ID) { - return "SELECT block_code FROM user_blocks WHERE id = " + USER_ID + ");"; +exports.paydroid = function(USER_ID,ROLE,VERSION) { + if (VERSION===1) { + return "SELECT a.current_total, b.delayed_total, c.days_to_payment, c.total_transactions FROM (SELECT count(*) AS current_total, 1 AS merge FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) a LEFT JOIN (SELECT count(*) AS delayed_total, 1 AS merge FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) b ON a.merge = b.merge LEFT JOIN (SELECT IFNULL(ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1),'No Data') AS days_to_payment, IFNULL(SUM(total_transactions),0) AS total_transactions, 1 AS merge FROM block_delays_duration WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH)) c ON b.merge = c.merge;" + + "SELECT a.staff_id, IFNULL(a.name,'Unmapped') AS name, a.task_assign, IFNULL(a.mobile_no,'Unmapped') AS mobile_no, a.block_code, a.block_name, a.unmapped, b.active, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, b.msr_no, b.work_name, b.work_code, b.panchayat_name, b.end_date, b.days_pending, b.step, b.type FROM (SELECT staff_id, name, task_assign, mobile_no, block_code, block_name, 0 AS unmapped FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") UNION SELECT a.staff_id, a.name, a.task_assign, a.mobile_no, b.block_code, b.block_name, 1 AS unmapped FROM (SELECT NULL as staff_id, NULL as name, NULL as task_assign, NULL as mobile_no, 1 as merge) a RIGHT JOIN (SELECT region_code as block_code, region_name as block_name, 1 as merge FROM user_regions WHERE user_id="+USER_ID+") b ON a.merge = b.merge ) a LEFT JOIN (SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, NULL as days_pending, NULL AS step, 'current_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 2) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 5) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code ) b ON a.staff_id=b.staff_id OR (a.staff_id IS NULL AND b.staff_id IS NULL AND a.block_code=b.block_code) LEFT JOIN (SELECT count(*) AS current_total, a.staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) c ON a.staff_id=c.staff_id OR (a.staff_id IS NULL AND c.staff_id IS NULL AND a.block_code=c.block_code) LEFT JOIN (SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code UNION SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) d ON a.staff_id=d.staff_id OR (a.staff_id IS NULL AND d.staff_id IS NULL AND a.block_code=d.block_code) ORDER BY active DESC, unmapped, delayed_total DESC, current_total DESC, staff_id;" + + "SELECT block_code, block_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,1) mrc_mre,ROUND(mre_wlg_mean,1) mre_wlg,ROUND(wlg_wls_mean,1) wlg_wls,ROUND(wls_fto_mean,1) wls_fto,ROUND(fto_firstsign_mean,1) fto_sn1,ROUND(firstsign_secondsign_mean,1) sn1_sn2,ROUND(secondsign_processed_mean,1) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') ORDER BY block_code, date;" + + "SELECT block_code, panchayat_code, panchayat_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,1) mrc_mre,ROUND(mre_wlg_mean,1) mre_wlg,ROUND(wlg_wls_mean,1) wlg_wls,ROUND(wls_fto_mean,1) wls_fto,ROUND(fto_firstsign_mean,1) fto_sn1,ROUND(firstsign_secondsign_mean,1) sn1_sn2,ROUND(secondsign_processed_mean,1) sn2_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') ORDER BY panchayat_code, date;" + + "SELECT * FROM notifications WHERE user_id = '"+USER_ID+"';" + + "SELECT state_code FROM blocks WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY state_code;" + + "SELECT * FROM contact;"; + } else if (VERSION===2) { + if (ROLE==='block') { + return "SELECT a.region_code as block_code, a.region_name as block_name, IFNULL(b.current_total,0) AS current_total, IFNULL(c.delayed_total,0) AS delayed_total, IFNULL(d.days_to_payment,'No Data') AS days_to_payment FROM (SELECT region_code, region_name FROM user_regions WHERE user_id='"+USER_ID+"') a LEFT JOIN (SELECT count(*) AS current_total, block_code AS region_code FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY region_code) b ON a.region_code = b.region_code LEFT JOIN (SELECT count(*) AS delayed_total, block_code AS region_code FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY region_code) c ON a.region_code = c.region_code LEFT JOIN (SELECT ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1) AS days_to_payment, block_code AS region_code FROM block_delays_duration WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY region_code) d ON a.region_code = d.region_code;" + + "SELECT a.staff_id, IFNULL(a.name,'Unmapped') AS name, a.task_assign, IFNULL(a.mobile_no,'') AS mobile_no, a.block_code, a.block_name, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, b.msr_no, b.work_name, b.work_code, b.panchayat_name, b.end_date, b.days_pending, b.step, b.type FROM (SELECT staff_id, name, task_assign, mobile_no, block_code, block_name FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") UNION SELECT a.staff_id, a.name, a.task_assign, a.mobile_no, b.block_code, b.block_name FROM (SELECT NULL as staff_id, NULL as name, NULL as task_assign, NULL as mobile_no, 1 as merge) a RIGHT JOIN (SELECT region_code as block_code, region_name as block_name, 1 as merge FROM user_regions WHERE user_id="+USER_ID+") b ON a.merge = b.merge ) a LEFT JOIN (SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, NULL as days_pending, NULL AS step, 'current_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 2) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 5) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code ) b ON a.staff_id=b.staff_id OR (a.staff_id IS NULL AND b.staff_id IS NULL AND a.block_code=b.block_code) LEFT JOIN (SELECT count(*) AS current_total, a.staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) c ON a.staff_id=c.staff_id OR (a.staff_id IS NULL AND c.staff_id IS NULL AND a.block_code=c.block_code) LEFT JOIN (SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code UNION SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) d ON a.staff_id=d.staff_id OR (a.staff_id IS NULL AND d.staff_id IS NULL AND a.block_code=d.block_code) WHERE a.staff_id IS NOT NULL OR (a.staff_id IS NULL AND (c.current_total>0 OR d.delayed_total>0));" + + "SELECT block_code, block_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),1) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),1) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),1) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),1) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),1) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),1) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),1) sn2_prc, ROUND(sum(mrc_processed_mean*total_transactions)/sum(total_transactions),1) mrc_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), block_code ORDER BY block_code, date;" + + "SELECT block_code, panchayat_code, panchayat_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),1) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),1) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),1) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),1) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),1) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),1) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),1) sn2_prc, ROUND(sum(mrc_processed_mean*total_transactions)/sum(total_transactions),1) mrc_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), panchayat_code ORDER BY panchayat_code, date;" + + "SELECT state_code FROM blocks WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY state_code;" + + "SELECT * FROM contact;" + + "SELECT * FROM paydroid_version;" + + "SELECT * FROM user_regions WHERE user_id="+USER_ID+";"; + } else if (ROLE=='district') { + return "SELECT a.region_code as district_code, a.region_name as district_name, IFNULL(b.current_total,0) AS current_total, IFNULL(c.delayed_total,0) AS delayed_total, IFNULL(d.days_to_payment,'No Data') AS days_to_payment FROM (SELECT region_code, region_name FROM user_regions WHERE user_id='"+USER_ID+"') a LEFT JOIN (SELECT count(*) AS current_total, b.district_code AS region_code FROM current_musters a INNER JOIN (SELECT district_code, block_code from blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code GROUP BY region_code ) b ON a.region_code = b.region_code LEFT JOIN (SELECT count(*) AS delayed_total, b.district_code AS region_code FROM delayed_musters a INNER JOIN (SELECT district_code, block_code from blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code GROUP BY region_code ) c ON a.region_code = c.region_code LEFT JOIN (SELECT ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1) AS days_to_payment, district_code AS region_code FROM district_delays_duration WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY region_code) d ON a.region_code = d.region_code;" + + "SELECT a.district_code, a.district_name, a.block_code, a.block_name, j.firstname, j.lastname, IFNULL(j.designation,'No Data') AS designation, j.designation_id, IFNULL(j.mobile,'') AS mobile, IFNULL(b.days_to_payment,'No Data') AS days_to_payment, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, IFNULL(e.t2_total,0) AS t2_total, IFNULL(e.t2_avg,'') AS t2_avg, IFNULL(f.t5_total,0) AS t5_total, IFNULL(f.t5_avg,'') AS t5_avg, IFNULL(g.t6_total,0) AS t6_total, IFNULL(g.t6_avg,'') AS t6_avg, IFNULL(h.t7_total,0) AS t7_total, IFNULL(h.t7_avg,'') AS t7_avg, IFNULL(i.t8_total,0) AS t8_total, IFNULL(i.t8_avg,'') AS t8_avg FROM (SELECT district_code, district_name, block_code, block_name FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a LEFT JOIN (SELECT block_code, IFNULL(ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1),'No Data') AS days_to_payment FROM block_delays_duration WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH) GROUP BY block_code) b ON a.block_code=b.block_code LEFT JOIN (SELECT b.block_code, count(*) AS current_total FROM current_musters a RIGHT JOIN blocks b ON a.block_code=b.block_code AND b.district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") GROUP BY a.block_code) c ON a.block_code=c.block_code LEFT JOIN (SELECT b.block_code, count(*) AS delayed_total FROM delayed_musters a RIGHT JOIN blocks b ON a.block_code=b.block_code AND b.district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") GROUP BY a.block_code) d ON a.block_code=d.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t2_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 2),1) AS t2_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t2') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) e ON a.block_code=e.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t5_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 5),1) AS t5_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t5') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) f ON a.block_code=f.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t6_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 6),1) AS t6_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t6') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) g ON a.block_code=g.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t7_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 7),1) AS t7_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t7') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) h ON a.block_code=h.block_code LEFT JOIN (SELECT b.block_code, count(*) AS t8_total, ROUND(AVG(datediff(CURDATE(), a.end_date) - 8),1) AS t8_avg FROM (SELECT * FROM delayed_musters WHERE step='ds_t8') a INNER JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code=b.block_code GROUP BY b.block_code) i ON a.block_code=i.block_code LEFT JOIN (SELECT a.block_code, a.firstname, a.lastname, a.designation, a.designation_id, a.mobile FROM block_officers a RIGHT JOIN (SELECT * FROM blocks WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.block_code = b.block_code) j ON a.block_code=j.block_code;" + + "SELECT district_code, district_name,SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),1) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),1) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),1) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),1) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),1) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),1) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),1) sn2_prc,ROUND(sum(mrc_processed_mean*total_transactions)/sum(total_transactions),1) mrc_prc FROM district_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), district_code ORDER BY district_code, date;" + + "SELECT district_code, block_code, block_name, SUM(total_transactions) AS tot_trn,YEAR(date) AS year, MONTH(date) AS month,ROUND(sum(mrc_mre_mean*total_transactions)/sum(total_transactions),1) mrc_mre,ROUND(sum(mre_wlg_mean*total_transactions)/sum(total_transactions),1) mre_wlg,ROUND(sum(wlg_wls_mean*total_transactions)/sum(total_transactions),1) wlg_wls,ROUND(sum(wls_fto_mean*total_transactions)/sum(total_transactions),1) wls_fto,ROUND(sum(fto_firstsign_mean*total_transactions)/sum(total_transactions),1) fto_sn1,ROUND(sum(firstsign_secondsign_mean*total_transactions)/sum(total_transactions),1) sn1_sn2,ROUND(sum(secondsign_processed_mean*total_transactions)/sum(total_transactions),1) sn2_prc, ROUND(sum(mrc_processed_mean*total_transactions)/sum(total_transactions),1) mrc_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY YEAR(date), MONTH(date), block_code ORDER BY block_code, date;" + + "SELECT state_code FROM districts WHERE district_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY state_code;" + + "SELECT * FROM contact;" + + "SELECT * FROM paydroid_version;" + + "SELECT * FROM user_regions WHERE user_id="+USER_ID+";"; + } + } }; exports.outcomes = function() { @@ -51,23 +73,4 @@ exports.outcomes = function() { "SELECT * FROM estimates_summary;" + "SELECT date, mean, upper, outcome, lower, arm FROM estimates_series_arms;" + // arm === (1,2,3) "SELECT t1_mean, t2_mean, t3_mean, p_val, outcome FROM estimates_summary_arms;"; -}; - -exports.current_musters = function(BLOCK_CODE) { - return "SELECT IFNULL(a.name,'Unmapped') AS name, IFNULL(a.mobile_no,'Unmapped') AS mobile_no, b.msr_no, b.work_name, b.panchayat_name FROM (SELECT * FROM employees WHERE block_code='"+BLOCK_CODE+"' AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code='"+BLOCK_CODE+"') b ON a.map_location = b.panchayat_code ORDER BY name, panchayat_code, msr_no;" + - "SELECT IFNULL(a.total_panchayat_count,0) AS total_panchayat_count, IFNULL(b.grs_panchayat_count,0) AS grs_panchayat_count FROM (SELECT block_code, count(*) AS total_panchayat_count FROM panchayats WHERE block_code = '" + BLOCK_CODE + "') a LEFT JOIN (SELECT block_code, count(*) AS grs_panchayat_count FROM employees WHERE task_assign = 'GRS' AND block_code = '" + BLOCK_CODE + "') b ON a.block_code = b.block_code;"; -}; - -exports.delayed_musters = function(BLOCK_CODE) { - return "SELECT IFNULL(a.name,'Unmapped') AS name, IFNULL(a.mobile_no,'Unmapped') AS mobile_no, b.msr_no, b.work_name, b.panchayat_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') AS end_date, (datediff(CURDATE(), b.end_date) - 2) AS days_pending, b.step FROM (SELECT * FROM employees WHERE block_code='"+BLOCK_CODE+"' AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code='"+BLOCK_CODE+"' AND step='ds_t2') b ON a.map_location = b.panchayat_code UNION SELECT IFNULL(a.name,'Unmapped') AS name, IFNULL(a.mobile_no,'Unmapped') AS mobile_no, b.msr_no, b.work_name, b.panchayat_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') AS end_date, (datediff(CURDATE(), b.end_date) - 5) AS days_pending, b.step FROM (SELECT * FROM employees WHERE block_code='"+BLOCK_CODE+"' AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code='"+BLOCK_CODE+"' AND step='ds_t5') b ON a.map_location = b.panchayat_code UNION SELECT NULL AS name, NULL AS mobile_no, msr_no, work_name, panchayat_code, panchayat_name, DATE_FORMAT(end_date,'%d-%m-%Y') AS end_date, (datediff(CURDATE(), end_date) - CAST(REPLACE(step,'ds_t','') AS UNSIGNED)) AS days_pending, step FROM delayed_musters WHERE block_code='"+BLOCK_CODE+"' AND step NOT IN ('ds_t2','ds_t5') ORDER BY step, name, panchayat_code, msr_no;" + - "SELECT IFNULL(a.total_panchayat_count,0) AS total_panchayat_count, IFNULL(b.ta_panchayat_count,0) AS ta_panchayat_count, IFNULL(c.grs_panchayat_count,0) AS grs_panchayat_count FROM (SELECT block_code, count(*) AS total_panchayat_count FROM panchayats WHERE block_code = '" + BLOCK_CODE + "') a LEFT JOIN (SELECT block_code, count(*) AS ta_panchayat_count FROM employees WHERE task_assign = 'TA' AND block_code = '" + BLOCK_CODE + "') b ON a.block_code = b.block_code LEFT JOIN (SELECT block_code, count(*) AS grs_panchayat_count FROM employees WHERE task_assign = 'GRS' AND block_code = '" + BLOCK_CODE + "') c ON a.block_code = c.block_code;"; -}; - -exports.cards = function(USER_ID) { - return "SELECT a.current_total, b.delayed_total, c.time_to_payment, c.total_transactions FROM (SELECT count(*) AS current_total, 1 AS merge FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) a LEFT JOIN (SELECT count(*) AS delayed_total, 1 AS merge FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"')) b ON a.merge = b.merge LEFT JOIN (SELECT IFNULL(ROUND(SUM(mrc_processed_mean * total_transactions) / SUM(total_transactions),1),'No Data') AS time_to_payment, IFNULL(SUM(total_transactions),0) AS total_transactions, 1 AS merge FROM block_delays_duration WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') AND gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' and date>=DATE_SUB(now(), INTERVAL 3 MONTH)) c ON b.merge = c.merge;" + - "SELECT a.staff_id, IFNULL(a.name,'Unmapped') AS name, a.task_assign, IFNULL(a.mobile_no,'Unmapped') AS mobile_no, a.block_code, a.block_name, a.unmapped, b.active, IFNULL(c.current_total,0) AS current_total, IFNULL(d.delayed_total,0) AS delayed_total, b.msr_no, b.work_name, b.work_code, b.panchayat_name, b.end_date, b.days_pending, b.step, b.type FROM (SELECT staff_id, name, task_assign, mobile_no, block_code, block_name, 0 AS unmapped FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") UNION SELECT a.staff_id, a.name, a.task_assign, a.mobile_no, b.block_code, b.block_name, 1 AS unmapped FROM (SELECT NULL as staff_id, NULL as name, NULL as task_assign, NULL as mobile_no, 1 as merge) a RIGHT JOIN (SELECT region_code as block_code, region_name as block_name, 1 as merge FROM user_regions WHERE user_id="+USER_ID+") b ON a.merge = b.merge ) a LEFT JOIN (SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, NULL as days_pending, NULL AS step, 'current_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 2) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code UNION SELECT a.staff_id, 1 AS active, b.block_code, b.msr_no, b.work_name, b.work_code, b.panchayat_name, DATE_FORMAT(b.end_date,'%d-%m-%Y') as end_date, (datediff(CURDATE(), b.end_date) - 5) AS days_pending, b.step, 'delayed_musters' AS type FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code ) b ON a.staff_id=b.staff_id OR (a.staff_id IS NULL AND b.staff_id IS NULL AND a.block_code=b.block_code) LEFT JOIN (SELECT count(*) AS current_total, a.staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) a RIGHT JOIN (SELECT * FROM current_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+")) b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) c ON a.staff_id=c.staff_id OR (a.staff_id IS NULL AND c.staff_id IS NULL AND a.block_code=c.block_code) LEFT JOIN (SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='GRS') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t2') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code UNION SELECT count(*) AS delayed_total, staff_id, b.block_code FROM (SELECT * FROM employees WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND task_assign='TA') a RIGHT JOIN (SELECT * FROM delayed_musters WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id="+USER_ID+") AND step='ds_t5') b ON a.map_location = b.panchayat_code GROUP BY staff_id, b.block_code ) d ON a.staff_id=d.staff_id OR (a.staff_id IS NULL AND d.staff_id IS NULL AND a.block_code=d.block_code) ORDER BY active DESC, unmapped, delayed_total DESC, current_total DESC, staff_id;" + - "SELECT block_code, block_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,2) mrc_mre,ROUND(mre_wlg_mean,2) mre_wlg,ROUND(wlg_wls_mean,2) wlg_wls,ROUND(wls_fto_mean,2) wls_fto,ROUND(fto_firstsign_mean,2) fto_sn1,ROUND(firstsign_secondsign_mean,2) sn1_sn2,ROUND(secondsign_processed_mean,2) sn2_prc FROM block_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') ORDER BY block_code, date;" + - "SELECT block_code, panchayat_code, panchayat_name,total_transactions tot_trn,date,ROUND(mrc_mre_mean,2) mrc_mre,ROUND(mre_wlg_mean,2) mre_wlg,ROUND(wlg_wls_mean,2) wlg_wls,ROUND(wls_fto_mean,2) wls_fto,ROUND(fto_firstsign_mean,2) fto_sn1,ROUND(firstsign_secondsign_mean,2) sn1_sn2,ROUND(secondsign_processed_mean,2) sn2_prc FROM panchayat_delays_duration WHERE gender = 'both' AND bank_type = 'all' AND date_type = 'processed_date' AND total_transactions > 0 AND panchayat_code <> '0000000000' AND block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') ORDER BY panchayat_code, date;" + - "SELECT state_code FROM blocks WHERE block_code IN (SELECT region_code FROM user_regions WHERE user_id='"+USER_ID+"') GROUP BY state_code;" + - "SELECT * FROM contact;"; }; \ No newline at end of file diff --git a/app/helpers/utils.js b/app/helpers/utils.js index 2c2a5503..af05b9e1 100644 --- a/app/helpers/utils.js +++ b/app/helpers/utils.js @@ -1,6 +1,6 @@ 'use strict'; -var d3 = require('d3'); +const D3 = require('d3'); exports.padNum = function(num) { var str = num.toString(); @@ -18,7 +18,7 @@ exports.flatten = function(obj) { }; exports.nestEmpMapping = function(obj) { - return d3.nest() + return D3.nest() .key(function(d) { return d.region_code; }) @@ -29,7 +29,7 @@ exports.nestEmpMapping = function(obj) { }; exports.nestEmpStats = function(obj) { - return d3.nest() + return D3.nest() .key(function(d) { return d.staff_id; }) @@ -42,17 +42,28 @@ exports.nestEmpStats = function(obj) { .map(exports.flatten(obj)); }; -exports.getDesignation = function(task_assign,state_code) { +exports.getDesignation = function(task_assign, state_code) { var designationLookup = { - 17:'SE', - 33:'TA', - 34:'JE' + 17: 'SE', + 33: 'TA', + 34: 'JE' }; if (task_assign === 'TA') { return designationLookup[state_code]; - } - else { + } else { return task_assign; } +}; + +exports.buildSubject = function(subjectStub, regionsResponse) { + var subjectLine = subjectStub + ' ['; + for (var i=0; i0) { + subjectLine += '/'; + } + subjectLine += regionsResponse[i].region_name + ' (' + regionsResponse[i].region_code + ')'; + } + subjectLine += ']'; + return subjectLine; } diff --git a/app/locales/en_US/index.js b/app/locales/en_US/index.js deleted file mode 100644 index 9bd2d20b..00000000 --- a/app/locales/en_US/index.js +++ /dev/null @@ -1,256 +0,0 @@ -'use strict'; - -module.exports = { - $meta: 'English translation file', - profile: { - firstname: 'First Name', - lastname: 'Last Name', - profile: 'Profile', - account: 'Account', - work_email: 'Work Email', - mobile: 'Mobile', - personal_email: 'Personal Email', - lang : 'Language', - settings: 'Settings', - logout: 'Logout', - profile_settings: 'Profile Settings', - email_settings: 'Email Settings', - primary_email_msg: 'Your primary email address will be used for account-related notifications as well as any web-based operations.', - save: 'Update', - your_primary_email: 'Your primary email', - change_pass: 'Change password', - old_pass: 'Old password', - new_pass: 'New password', - pass_confirm:'Verify new password', - forgot_pass: 'I forgot my password' - }, - navigation: { - overview: { - $filter: 'role', - district: 'District Performance', - block: 'Block Performance', - $default: 'Overview Performance' - }, - discrete: { - $filter: 'role', - district: 'Block Performance', - block: 'Panchayat Performance', - $default: 'Discrete Performance' - }, - current: 'Current musters', - delayed: 'Delayed musters' - }, - notifications : { - read : 'Read Notifications', - unread : 'Unread Notifications', - message: { - 1: { - $filter: 'role', - block: [' block made ',' payments to MGNREGA beneficiaries on ',' .'], - district: [' district made ',' payments to MGNREGA beneficiaries on ',' .'] - }, - 2: { - main: ['The average time from muster roll closure to bank processing for these transactions was ',' days, ',' the mandated maximum of 15 days.'], - comparison: ['greater than','equal to','less than'] - } - } - }, - browser_msg: 'The browser you are using is not supported. PayDash works best with Chrome, Firefox, or Internet Explorer 9+.', - messages: { - loading: 'Loading data...', - not_found: 'Page not found. Please contact the PayDash team if you need assistance.' - }, - time_selector: { - '1': 'All available dates', - '2': 'Past 60 days', - '3': 'Past 30 days' - }, - payment_steps: { - '1': 'Muster roll closure to muster roll entry', - '2': 'Muster roll entry to wage list generation', - '3': 'Wage list generation to wage list sent', - '4': 'Wage list sent to FTO generation', - '5': 'FTO generation to first signature', - '6': 'First signature to second signature', - '7': 'Second signature to processed by bank' - }, - payment_steps_labels: [ - 'Muster roll closure to muster roll entry', - 'Muster roll entry to wage list generation', - 'Wage list generation to wage list sent', - 'Wage list sent to FTO generation', - 'FTO generation to first signature', - 'First signature to second signature', - 'Second signature to processed by bank' - ], - compare_chart_labels: { - 'state': 'state average', - 'district': 'district average', - 'block': 'block average' - }, - y_axis_labels: 'Days to complete process', - total_trans: "Total transactions on", - performance: { - overview: { - chart_a: { - title: { - $filter: 'role', - district: 'District Performance', - block: 'Your Block\'s Performance', - $default: 'Overview Performance' - }, - description: { - $filter: 'role', - district: 'Average number of days to complete each step of the payment process in your district.', - block: 'Average number of days to complete each step of the payment process in your block.', - $default: 'Average number of days to complete each step of the payment process in your region.' - } - }, - chart_b: { - title: { - $filter: 'role', - district: 'Benchmarking Your Performance', - block: 'Benchmarking Your Performance', - $default: 'Benchmarking Your Performance' - }, - description: { - $filter: 'role', - district: 'Compare your performance with averages for your state.', - block: 'Compare your performance with averages for your district and state.', - $default: 'Compare your performance with averages for other regions.' - } - }, - tooltip: 'The chart at right shows the average number of days to complete each step of the payment process for payments that reached beneficiaries’ bank accounts on the given date. Therefore, only completed payments are displayed.', - }, - discrete: { - sub_heading: { - 1: 'Performance of', - 2: 'block/panchayat' - }, - subtitle: { - $filter: 'role', - block: 'The performance of your panchayat on average days to complete each step of the payment process.', - district: 'The performance of your blocks/panchayats on average days to complete each step of the payment process.', - $default: 'The performance of your regions on average days to complete each step of the payment process.' - }, - tooltip: 'The charts below show the average number of days to complete each step of the payment process for payments that reached beneficiaries’ bank accounts on the given date. Therefore, only completed payments are displayed. Your worst performing panchayats are shown first.', - ta_message: 'Your block has unmapped panchayats for the TA designation. As a result, we can\'t show you the performance of all the TA\'s in your block. Please visit the MGNREGA portal at nrega.nic.in to complete your TA mapping.', - grs_message: 'Your block has unmapped panchayats for the GRS designation. As a result, we can\'t show you the performance of all the GRS\'s in your block. Please visit the MGNREGA portal at nrega.nic.in to complete your GRS mapping.', - panchayat_chart_placeholder: 'Select a block or panchayat at left to view its payment performance', - grouping_selectors: { - no: 'No Grouping', - ta: 'Group by TA', - grs: 'Group by GRS' - }, - sidebar : { - total_trans: 'Total Transactions', - avg_days: 'Avg. days from muster roll closure to entry' - } - } - }, - musters: { - current: { - title: 'Musters Closing Today' - }, - delayed: { - title: 'Delayed Musters', - t_2: 'Attendance not filled (T+2)', - t_5: 'Measurement book not filled (T+5)', - t_6: 'Wagelist not sent (T+6)', - t_7: 'Pending for FTO first signature (T+7)', - t_8: 'Pending for FTO second signature (T+8)' - } - }, - app: { - overview: { - musters_closing_today: 'Musters closing today', - delayed_musters: 'Delayed musters', - total_transactions: 'Transactions in last 3 months', - days_to_payment: 'Days to payment in last 3 months', - cards_need_attention: 'cards require your attention', - view_cards: 'VIEW CARDS' - }, - cards: { - musters_closing_today: 'musters closing today', - delayed_musters_1: 'delayed musters', - muster_details: 'MUSTER DETAILS', - current_musters: 'CURRENT MUSTERS', - delayed_musters_2: 'DELAYED MUSTERS', - work_code: 'Work code', - work_name: 'Work name', - closure_date: 'Closure date', - days_delayed: 'Days delayed' - }, - chart: { - days_to_complete_process: 'Days to complete process', - steps: { - 1: 'MR Closure to MR Entry', - 2: 'MR Entry to Wage List Generation', - 3: 'Wage List Generation to Wage List Sent', - 4: 'Wage List Sent to FTO Generation', - 5: 'FTO Generation to 1st Sign', - 6: '1st Sign to 2nd Sign', - 7: '2nd Sign to Bank Processing', - all: 'All steps' - }, - dates: { - all_dates: 'All dates', - last_60: 'Last 60 days', - last_30: 'Last 30 days' - }, - regions: { - panchayat: 'Panchayat', - block: 'Block', - }, - tooltip: { - date: 'Date', - days: 'Avg. days', - transactions: 'Transactions', - step: 'Step' - } - }, - notifications: { - notifications: 'Notifications', - read: 'Read', - unread: 'Unread' - }, - profile: { - firstname: 'First Name', - lastname: 'Last Name', - profile: 'Profile', - account: 'Account', - work_email: 'Work Email', - mobile: 'Mobile', - personal_email: 'Personal Email', - lang: 'Language', - settings: 'Settings', - logout: 'Logout', - profile_settings: 'Profile Settings', - email_settings: 'Email Settings', - primary_email_msg: 'Your primary email address will be used for account-related notifications as well as any web-based operations.', - save: 'Update', - your_primary_email: 'Your primary email', - change_pass: 'Change password', - old_pass: 'Old password', - new_pass: 'New password', - pass_confirm: 'Verify new password', - forgot_pass: 'I forgot my password' - }, - messages: { - login: { - connectivity: 'Unable to log in to PayDash. Please try again when your device has internet connectivity.', - credentials: 'Incorrect username/password combination. Please contact the PayDash team if this issue persists.', - general: 'Unable to log in to PayDash. Please contact the PayDash team if this issue persists.' - }, - logout: { - connectivity: 'Unable to log out of PayDash. Please try again when your device has internet connectivity.', - warning: { - 'message':'Are you sure you want to log out? PayDash offline mode is only available if you stay logged in.', - 'logout': 'Log out', - 'cancel': 'Cancel' - }, - general: 'Unable to log out of PayDash. Please contact the PayDash team if this issue persists.' - } - } - } -}; diff --git a/app/locales/en_US/v1.js b/app/locales/en_US/v1.js new file mode 100644 index 00000000..8513cd82 --- /dev/null +++ b/app/locales/en_US/v1.js @@ -0,0 +1,223 @@ +'use strict'; + +module.exports = { + $meta: 'English translation file', + web: { + navigation: { + overview: 'OVERVIEW', + musters: { + $filter: 'role', + district: 'BLOCKS', + block: 'MUSTERS' + }, + performance: 'PERFORMANCE' + }, + overview: { + current: 'CURRENT', + delayed: 'DELAYED', + days_to_payment: 'DAYS TO PAYMENT', + welcome: { + 1: 'Hello', + 2: 'ji' + }, + description: { + $filter : 'role', + block: 'Here\'s how your Block is doing on MGNREGA payment delays.', + district: 'Here\'s how your District is doing on MGNREGA payment delays.' + } + }, + musters: { + current: 'CURRENT', + delayed: 'DELAYED', + muster_details: 'MUSTER DETAILS', + officers: 'OFFICERS', + current_musters: 'CURRENT MUSTERS', + delayed_musters: 'Delayed MUSTERS', + msr_no: 'MUSTER NO.', + panchayat_name: 'PANCHAYAT NAME', + work_name: 'WORK NAME', + work_code: 'WORK CODE', + closure_date: 'CLOSURE DATE', + days_pending: 'DAYS PENDING', + current_total: 'CURRENT TOTAL', + delayed_total: 'DELAYED TOTAL', + name: 'NAME', + designation: 'DESIGNATION', + block_name: 'BLOCK NAME', + days_to_payment: 'DAYS TO PAYMENT', + no_muster_information: 'There is no muster information available', + sort_by: 'Sort By', + search_placeholder: 'Search' + }, + performance: { + overview: { + title: { + $filter: 'role', + district: 'District Performance', + block: 'Your Block/Panchayat\'s Performance', + $default: 'Overview Performance' + }, + description: { + $filter: 'role', + district: 'Average number of days to complete each step of the payment process in your district.', + block: 'Average number of days to complete each step of the payment process in your block.', + $default: 'Average number of days to complete each step of the payment process in your region.' + }, + labels: [ + 'Muster roll closure to muster roll entry', + 'Muster roll entry to wage list generation', + 'Wage list generation to wage list sent', + 'Wage list sent to FTO generation', + 'FTO generation to first signature', + 'First signature to second signature', + 'Second signature to processed by bank' + ], + tooltip: 'The chart at right shows the average number of days to complete each step of the payment process for payments that reached beneficiaries’ bank accounts on the given date. Therefore, only completed payments are displayed.', + }, + comparison: { + title: { + $filter: 'role', + district: 'Benchmarking Your Performance', + block: 'Benchmarking Your Performance', + $default: 'Benchmarking Your Performance' + }, + description: { + $filter: 'role', + district: 'Compare your performance with averages for your state.', + block: 'Compare your performance with averages for your district and state.', + $default: 'Compare your performance with averages for other regions.' + }, + labels: { + 'state': 'state average', + 'district': 'district average', + 'block': 'block average', + 'panchayat': 'panchayat average', + }, + total_trans: { + 'state': 'Total state transactions in', + 'district': 'Total district transactions in', + 'block': 'Total block transactions in', + 'panchayat': 'Total panchayat transactions in', + }, + tooltip: 'The chart at right shows the average number of days to complete each step of the payment process for payments that reached beneficiaries’ bank accounts on the given date. Therefore, only completed payments are displayed.', + }, + y_axis_label: 'Days to complete process', + total_trans: 'Total transactions in' + }, + profile: { + firstname: 'First Name', + lastname: 'Last Name', + profile: 'Profile', + account: 'Account', + work_email: 'Work Email', + mobile: 'Mobile', + personal_email: 'Personal Email', + lang: 'Language', + settings: 'Settings', + logout: 'Logout', + profile_settings: 'Profile Settings', + email_settings: 'Email Settings', + primary_email_msg: 'Your primary email address will be used for account-related notifications as well as any web-based operations.', + save: 'Update', + your_primary_email: 'Your primary email', + change_pass: 'Change password', + old_pass: 'Old password', + new_pass: 'New password', + pass_confirm: 'Verify new password', + forgot_pass: 'I forgot my password', + colorblind: 'Colorblind' + }, + }, + app: { + overview: { + musters_closing_today: 'Musters closing today', + delayed_musters: 'Delayed musters', + total_transactions: 'Transactions in last 3 months', + days_to_payment: 'Days to payment in last 3 months', + cards_need_attention: 'cards require your attention', + view_cards: 'VIEW CARDS' + }, + cards: { + musters_closing_today: 'musters closing today', + delayed_musters_1: 'delayed musters', + muster_details: 'MUSTER DETAILS', + current_musters: 'CURRENT MUSTERS', + delayed_musters_2: 'DELAYED MUSTERS', + work_code: 'Work code', + work_name: 'Work name', + closure_date: 'Closure date', + days_delayed: 'Days delayed' + }, + chart: { + days_to_complete_process: 'Days to complete process', + steps: { + 1: 'MR Closure to MR Entry', + 2: 'MR Entry to Wage List Generation', + 3: 'Wage List Generation to Wage List Sent', + 4: 'Wage List Sent to FTO Generation', + 5: 'FTO Generation to 1st Sign', + 6: '1st Sign to 2nd Sign', + 7: '2nd Sign to Bank Processing', + all: 'All steps' + }, + dates: { + all_dates: 'All dates', + last_60: 'Last 60 days', + last_30: 'Last 30 days' + }, + regions: { + panchayat: 'Panchayat', + block: 'Block', + }, + tooltip: { + date: 'Date', + days: 'Avg. days', + transactions: 'Transactions', + step: 'Step' + } + }, + notifications: { + notifications: 'Notifications', + read: 'Read', + unread: 'Unread' + }, + profile: { + firstname: 'First Name', + lastname: 'Last Name', + profile: 'Profile', + account: 'Account', + work_email: 'Work Email', + mobile: 'Mobile', + personal_email: 'Personal Email', + lang: 'Language', + settings: 'Settings', + logout: 'Logout', + profile_settings: 'Profile Settings', + email_settings: 'Email Settings', + primary_email_msg: 'Your primary email address will be used for account-related notifications as well as any web-based operations.', + save: 'Update', + your_primary_email: 'Your primary email', + change_pass: 'Change password', + old_pass: 'Old password', + new_pass: 'New password', + pass_confirm: 'Verify new password', + forgot_pass: 'I forgot my password' + }, + messages: { + login: { + connectivity: 'Unable to log in to PayDash. Please try again when your device has internet connectivity.', + credentials: 'Incorrect username/password combination. Please contact the PayDash team if this issue persists.', + general: 'Unable to log in to PayDash. Please contact the PayDash team if this issue persists.' + }, + logout: { + connectivity: 'Unable to log out of PayDash. Please try again when your device has internet connectivity.', + warning: { + 'message': 'Are you sure you want to log out? PayDash offline mode is only available if you stay logged in.', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'Unable to log out of PayDash. Please contact the PayDash team if this issue persists.' + } + } + } +}; diff --git a/app/locales/en_US/v2.js b/app/locales/en_US/v2.js new file mode 100644 index 00000000..0e47cd9b --- /dev/null +++ b/app/locales/en_US/v2.js @@ -0,0 +1,276 @@ +'use strict'; + +module.exports = { + $meta: 'English translation file', + app: { + $filter: 'role', + block: { + paydash: 'PayDash', + overview: { + musters_closing_today: 'Musters closing today', + delayed_musters: 'Delayed musters', + total_transactions: 'Transactions in last 3 months', + days_to_payment: 'Avg. days to payment in last 3 months', + cards_need_attention: 'cards require your attention', + view_cards: 'VIEW CARDS' + }, + cards: { + cards: 'Cards', + musters_closing_today: 'Musters closing today', + delayed_musters_1: 'Delayed musters', + muster_details: 'Muster details', + current_musters: 'CURRENT MUSTERS', + delayed_musters_2: 'DELAYED MUSTERS', + work_code: 'Work code', + work_name: 'Work name', + closure_date: 'Closure date', + days_delayed: 'Days delayed', + step: 'Step', + ds_t2: 'Attendance not filled (T+2)', + ds_t5: 'Measurement book not filled (T+5)', + ds_t6: 'Wagelist not sent (T+6)', + ds_t7: 'Pending for FTO first signature (T+7)', + ds_t8: 'Pending for FTO second signature (T+8)', + contact: { + phone: 'Phone', + whatsapp: 'WhatsApp' + } + }, + chart: { + days_to_complete_process: 'Days to complete process', + steps: { + 1: 'MR Closure to MR Entry', + 2: 'MR Entry to Wage List Generation', + 3: 'Wage List Generation to Wage List Sent', + 4: 'Wage List Sent to FTO Generation', + 5: 'FTO Generation to 1st Sign', + 6: '1st Sign to 2nd Sign', + 7: '2nd Sign to Bank Processing', + total: 'Total time for payment (overall)', + all: 'Total time for payment (step-wise)' + }, + statutory_limit: 'Statutory Limit', + dates: { + all_dates: 'All dates', + past_3_months: 'Past 3 months' + }, + regions: { + panchayat: 'Panchayat', + block: 'Block' + }, + tooltip: { + date: 'Date', + days: 'Avg. days', + transactions: 'Transactions', + step: 'Step' + } + }, + user_dropdown: { + profile: 'Profile', + logout: 'Logout' + }, + profile: { + profile: 'Profile', + edit: 'EDIT', + save:'SAVE', + updating:'UPDATING...', + firstname: 'First Name', + lastname: 'Last Name', + mobile: 'Mobile', + personal_email: 'Personal Email', + work_email: 'Work Email', + colorblind: 'Use Colorblind-Safe Theme', + lang: 'Language', + eng: 'English', + hindi: 'Hindi', + change_pass_button: 'CHANGE PASSWORD' + }, + password: { + change_pass: 'Change password', + old_pass: 'Old password', + new_pass: 'New password', + pass_confirm: 'Verify new password', + forgot_pass: 'I forgot my password', + change_pass_button: 'CHANGE PASSWORD', + }, + search: 'Search for TA/GRS...', + sort: { + current_total: 'Musters closing today', + delayed_total: 'Delayed musters', + name: 'Name', + designation: 'Designation' + }, + messages: { + login: { + connectivity: 'Unable to log in to PayDash. Please try again when your device has internet connectivity.', + credentials: 'Incorrect username/password combination. Please contact the PayDash team if this issue persists.', + general: 'Unable to log in to PayDash. Please contact the PayDash team if this issue persists.', + ga_account: 'The Google Account associated with this device does not match the Google Account associated with your PayDash account. Please contact the PayDash team if you require assistance.', + deactivated: 'Your account has been deactivated. Please contact the PayDash team if you require assistance.' + }, + logout: { + connectivity: 'Unable to log out of PayDash. Please try again when your device has internet connectivity.', + warning: { + 'message':'Are you sure you want to log out? PayDash offline mode is only available if you stay logged in.', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'Unable to log out of PayDash. Please contact the PayDash team if this issue persists.', + logging_out: 'Logging out...' + }, + profile_success: 'Profile successfully updated.', + profile_error: 'Unable to update profile. Please contact the PayDash team if this issue persists.', + password_success: 'Password changed successfully.', + password_wrong_old: 'Old password is incorrect. Please contact the PayDash team if you require assistance.', + password_new_nomatch: 'New password does not match.', + password_tooshort: 'Your new password must be at least 6 characters long.', + password_network_error: 'Unable to change password. Please try again when you have network connectivity.', + password_empty: 'Password cannot be empty', + requesting_change: 'Requesting password change...', + update_available: 'New Update Available', + update: 'Update', + grant_permission:'Please grant permission to proceed' + }, + contact: { + contact: 'Contact', + gmail: 'Gmail', + phone: 'Phone' + }, + whatsapp: { + overview:'Muster Roll Details for {name}\n\n{current_total} musters closing today\n{delayed_total} delayed musters\n\n', + current:'MUSTERS CLOSING TODAY\n\n_Msr_\n{msr_no}\n_Panchayat_\n{panchayat_name}\n_Work code_\n{work_code}\n_Work name_\n{work_name}\n_Closure date_\n{closure_date}\n\n', + delayed:'DELAYED MUSTERS\n\n_Msr_\n{msr_no}\n_Panchayat_\n{panchayat_name}\n_Work code_\n{work_code}\n_Work name_\n{work_name}\n_Closure date_\n{closure_date}\n_Days delayed_\n{days_pending}\n\n' + } + }, + district: { + paydash: 'PayDash', + overview: { + view_your_blocks: 'View your {blocks_total} blocks', + show_blocks: 'GO TO BLOCKS', + days_to_payment: 'Avg. days to payment in last 3 months', + musters_closing_today: 'Musters closing today', + delayed_musters: 'Delayed musters' + }, + cards: { + cards: 'Cards', + days_to_payment: 'Avg. days to payment in last 3 months', + musters_closing_today: 'Musters closing today', + delayed_musters: 'Delayed musters', + musters_diff_steps: 'Musters delayed at different steps', + avg_days_pending: 'Avg. days pending', + total: 'Total', + t_2: 'Attendance not filled (T+2)', + t_5: 'Measurement book not filled (T+5)', + t_6: 'Wagelist not sent (T+6)', + t_7: 'Pending for FTO first signature (T+7)', + t_8: 'Pending for FTO second signature (T+8)', + contact: { + phone: 'Phone', + whatsapp: 'WhatsApp' + } + }, + chart: { + days_to_complete_process: 'Days to complete process', + steps: { + 1: 'MR Closure to MR Entry', + 2: 'MR Entry to Wage List Generation', + 3: 'Wage List Generation to Wage List Sent', + 4: 'Wage List Sent to FTO Generation', + 5: 'FTO Generation to 1st Sign', + 6: '1st Sign to 2nd Sign', + 7: '2nd Sign to Bank Processing', + total: 'Total time for payment (overall)', + all: 'Total time for payment (step-wise)' + }, + statutory_limit: 'Statutory Limit', + dates: { + all_dates: 'All dates', + past_3_months: 'Past 3 months' + }, + regions: { + block: 'Block', + district: 'District' + }, + tooltip: { + date: 'Date', + days: 'Avg. days', + transactions: 'Transactions', + step: 'Step' + } + }, + user_dropdown: { + profile: 'Profile', + logout: 'Logout' + }, + profile: { + profile: 'Profile', + edit: 'EDIT', + save:'SAVE', + updating:'UPDATING...', + firstname: 'First Name', + lastname: 'Last Name', + mobile: 'Mobile', + personal_email: 'Personal Email', + work_email: 'Work Email', + colorblind: 'Use Colorblind-Safe Theme', + lang: 'Language', + eng: 'English', + hindi: 'Hindi', + change_pass_button: 'CHANGE PASSWORD' + }, + password: { + change_pass: 'Change password', + old_pass: 'Old password', + new_pass: 'New password', + pass_confirm: 'Verify new password', + forgot_pass: 'I forgot my password', + change_pass_button: 'CHANGE PASSWORD', + }, + search: 'Search for Block or Officer Name...', + sort: { + current_total: 'Musters closing today', + delayed_total: 'Delayed musters', + days_to_payment: 'Avg. days to payment in last 3 months', + block_name: 'Block name', + ceo_name: 'Block CEO name' + }, + messages: { + login: { + connectivity: 'Unable to log in to PayDash. Please try again when your device has internet connectivity.', + credentials: 'Incorrect username/password combination. Please contact the PayDash team if this issue persists.', + general: 'Unable to log in to PayDash. Please contact the PayDash team if this issue persists.', + ga_account: 'The Google Account associated with this device does not match the Google Account associated with your PayDash account. Please contact the PayDash team if you require assistance.', + deactivated: 'Your account has been deactivated. Please contact the PayDash team if you require assistance.' + }, + logout: { + connectivity: 'Unable to log out of PayDash. Please try again when your device has internet connectivity.', + warning: { + 'message':'Are you sure you want to log out? PayDash offline mode is only available if you stay logged in.', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'Unable to log out of PayDash. Please contact the PayDash team if this issue persists.', + logging_out: 'Logging out...' + }, + profile_success: 'Profile successfully updated.', + profile_error: 'Unable to update profile. Please contact the PayDash team if this issue persists.', + password_success: 'Password changed successfully.', + password_wrong_old: 'Old password is incorrect. Please contact the PayDash team if you require assistance.', + password_new_nomatch: 'New password does not match.', + password_tooshort: 'Your new password must be at least 6 characters long.', + password_network_error: 'Unable to change password. Please try again when you have network connectivity.', + password_empty: 'Password cannot be empty', + requesting_change: 'Requesting password change...', + update_available: 'New Update Available', + update: 'Update', + grant_permission:'Please grant permission to proceed' + }, + contact: { + contact: 'Contact', + gmail: 'Gmail', + phone: 'Phone' + }, + whatsapp: 'MGNREGA Payment Delay Performance for {name}\n\n_Block_\n{block_name}\n\n{days_to_payment} days to complete payment\n{current_total} musters closing today\n{delayed_total} delayed musters\n\nMUSTERS DELAYED AT DIFFERENT STEPS\n\n*Attendance not filled (T+2)*\n_Total_\n{t2_total}\n_Avg. days pending_\n{t2_avg}\n\n*Measurement book not filled (T+5)*\n_Total_\n{t5_total}\n_Avg. days pending_\n{t5_avg}\n\n*Wagelist not sent (T+6)*\n_Total_\n{t6_total}\n_Avg. days pending_\n{t6_avg}\n\n*Pending for FTO first signature (T+7)*\n_Total_\n{t7_total}\n_Avg. days pending_\n{t7_avg}\n\n*Pending for FTO second signature (T+8)*\n_Total_\n{t8_total}\n_Avg. days pending_\n{t8_avg}\n' + } + } +}; diff --git a/app/locales/hi/index.js b/app/locales/hi/index.js deleted file mode 100644 index 0f2f273d..00000000 --- a/app/locales/hi/index.js +++ /dev/null @@ -1,260 +0,0 @@ -'use strict'; - -module.exports = { - $meta: 'Hindi translation file', - profile: { - firstname: 'मूल नाम', - lastname: 'उपनाम', - profile: 'प्रोफ़ाइल', - account: 'अकाउंट', - work_email: 'औपचारिक e-mail', - mobile: 'मोबाइल नंबर', - personal_email: 'निजी e-mail', - lang : 'भाषा', - settings: 'सेट्टिंग्स', - logout: 'लौग आउट', - profile_settings: 'आपकी प्रोफ़ाइल सेट्टिंग्स', - email_settings: 'E-Mail सेट्टिंग्स', - primary_email_msg: 'आपके अकाउंट से संबंधित संदेशों और इंटरनेट-संबंधित प्रक्रियाओं के लिए आपके मुख्य e-mail ID का उपयोग किया जाएगा.', - save: 'अद्यतन (update)', - your_primary_email: 'आपका मुख्य e-mail ID', - change_pass: 'पासवर्ड बदलें', - old_pass: 'पुराना पासवर्ड ', - new_pass: 'नया पासवर्ड ', - pass_confirm:'नये पासवर्ड को सत्यापित करें', - forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया' - }, - navigation: { - overview: { - $filter: 'role', - district: 'ज़िला प्रदर्शन', - block: 'प्रखंड/जनपद प्रदर्शन', - $default: 'अवलोकन प्रदर्शन' - }, - discrete: { - $filter: 'role', - district: 'प्रखंड/जनपद प्रदर्शन', - block: 'पंचायत प्रदर्शन', - $default: 'अलहदा प्रदर्शन' - }, - current: 'वर्तमान मस्टर्स', - delayed: 'विलंबित मस्टर्स' - }, - notifications : { - read : 'पठित संदेश', - unread : 'अपठित संदेश', - message: { - 1: { - $filter: 'role', - block: [' प्रखंड/जनपद में ',' तारीख को ',' MGNREGA भुगतान हुए |'], - district: [' ज़िला में ',' तारीख को ',' MGNREGA भुगतान हुए |'] - }, - 2: { - main: ['औसतन, मस्टर रोल बंद होने से बैंक की कारवाई के समापन के बीच ',' दिन लगे, जो की सरकार द्वारा नियमित 15-दिन की सीमा ',' है |'], - comparison: ['से ज़्यादा','के बराबर','से कम'] - } - } - }, - browser_msg: 'आपका browser इस वेबसाइट के लिए अनुकूल नहीं है. PayDash चलाने के लिए Chrome, Firefox या Internet Explorer 9 या ऊंचे संस्करण का उपयोग करें.', - messages: { - loading: 'डाटा लोड हो रहा है...', - not_found: 'पृष्ठ नहीं मिला। Paydash टीम से संपर्क करें.' - }, - time_selector :{ - '1': 'सारी उपलब्ध तिथियाँ', - '2': 'पिछले 60 दिन', - '3': 'पिछले 30 दिन' - }, - payment_steps: { - '1': 'मस्टर रोल बंद से डाटा एंट्री का समय', - '2': 'डाटा एंट्री से वेज लिस्ट बनाने का समय', - '3': 'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', - '4': 'वेज लिस्ट भेजने से FTO बनाने का समय', - '5': 'FTO बनाने से पहले हस्ताक्षर का समय', - '6': 'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', - '7': 'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय' - }, - payment_steps_labels: [ - 'मस्टर रोल बंद से डाटा एंट्री का समय', - 'डाटा एंट्री से वेज लिस्ट बनाने का समय', - 'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', - 'वेज लिस्ट भेजने से FTO बनाने का समय', - 'FTO बनाने से पहले हस्ताक्षर का समय', - 'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', - 'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय' - ], - compare_chart_labels:{ - 'state': 'राज्य औसत', - 'district': 'ज़िला औसत', - 'block': 'प्रखंड/जनपद औसत' - }, - y_axis_labels: 'प्रक्रिया पूरी करने में लगे दिन', - total_trans :"तिथि : कुल भुगतानों की संख्या-", - performance: { - overview: { - chart_a: { - title: { - $filter: 'role', - district: 'आपके ज़िले का प्रदर्शन', - block: 'आपके प्रखंड/जनपद का प्रदर्शन', - $default: 'अवलोकन प्रदर्शन' - }, - description: { - $filter: 'role', - district: 'आपके ज़िले में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन', - block: 'आपके प्रखंड/जनपद में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन', - $default: 'आपके क्षेत्रों में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन' - } - }, - chart_b: { - title: { - $filter: 'role', - district: 'आपके प्रदर्शन की तुलना', - block: 'आपके प्रदर्शन की तुलना', - $default: 'आपके प्रदर्शन की तुलना' - }, - description: { - $filter: 'role', - district: 'अपने ज़िले के औसत प्रदर्शन की तुलना राज्य के औसत प्रदर्शन से करें', - block: 'अपने प्रखंड/जनपद के औसत प्रदर्शन की तुलना ज़िले और राज्य के औसत प्रदर्शन से करें ', - $default: 'अपने प्रखंड/जनपद के औसत प्रदर्शन की तुलना अन्य क्षेत्रों के औसत प्रदर्शन से करें' - } - }, - tooltip: 'यह ग्राफ़ MGNREGA मज़दूरी भुगतान में लगा औसत समय दिखाता है| वर्णित तिथियों पर हुए भुगतान में लगे समय को 7 पड़ावों में बाटा गया है| इसलिए, केवल पूरे हुए भुगतान का डाटा दिखाया जा रहा है|', - }, - discrete:{ - sub_heading: { - '1' : { - $filter: 'role', - block: 'आपके जनपद/प्रखंड की पंचायत', - district: 'आपके ज़िले में प्रखंड/पंचायत' - }, - '2' : 'का प्रदर्शन' - }, - subtitle: { - $filter: 'role', - block: 'आपकी पंचायतों में मज़दूरी भुगतान की प्रक्रिया के हर एक पड़ाव में लगा औसत समय', - district: 'आपके प्रखंडों/पंचायतों में मज़दूरी भुगतान की प्रक्रिया के हर एक पड़ाव में लगा औसत समय', - $default :'अपने क्षेत्रों में मज़दूरी भुगतान की प्रक्रिया के हर एक पड़ाव में लगा औसत समय' - }, - tooltip: 'यह ग्राफ़ MGNREGA मज़दूरी भुगतान में लगा औसत समय दिखाता है| वर्णित तिथियों पर हुए भुगतान में लगे समय को 7 पड़ावों में बाटा गया है| इसलिए, केवल पूरे हुए भुगतान का डाटा दिखाया जा रहा है|', - ta_message: 'आपके प्रखंड/जनपद में कुछ TAs/SEs/JEs और उनकी पंचायतों के नाम MGNREGA वेबसाइट पर अपडेट नहीं किए गये हैं| इस के परिणाम स्वरूप, हम आपको आपके प्रखंड/जनपद के सभी TAs/SEs/JEs के प्रदर्शन की जानकारी नहीं दे सकते| यह जानकारी पाने के लिए कृपया nrega.nic.in पर सभी TAs/SEs/JEs और उनकी पंचायतों के नाम भरें|', - grs_message: 'आपके प्रखंड/जनपद में कुछ GRSs और उनकी पंचायतों के नाम MGNREGA वेबसाइट पर अपडेट नहीं किए गये हैं| इस के परिणाम स्वरूप, हम आपको आपके प्रखंड/जनपद के सभी GRSs के प्रदर्शन की जानकारी नहीं दे सकते| यह जानकारी पाने के लिए कृपया nrega.nic.in पर सभी GRSs और उनकी पंचायतों के नाम भरें|', - panchayat_chart_placeholder: 'भुगतान के प्रदर्शन को देखने के लिए एक पंचायत या प्रखंड/जनपद का चयन करें ', - grouping_selectors: { - no: 'बिना कोई वर्गीकरण', - ta:'वर्ग: उप यंत्री', - grs: 'वर्ग: GRS' - }, - sidebar : { - total_trans: 'कुल भुगतान ', - avg_days: 'पंचायतों में मस्टर रोल बंद से डाटा एंट्री में लगा समय (औसत)' - } - } - }, - musters: { - current: { - title: 'आज बंद हो रहे मस्टर्स' - }, - delayed:{ - title: 'विलंबित मस्टर्स', - t_2: 'अटेंडेन्स नहीं भरी गयी (T+2)', - t_5: 'MB नहीं भरी गयी (T+5)', - t_6: 'वेज लिस्ट नहीं भेजी गयी (T+6)', - t_7: 'FTO पर पहला हस्ताक्षर नहीं हुआ (T+7)', - t_8: 'FTO पर दूसरा हस्ताक्षर नहीं हुआ (T+8)' - } - }, - app: { - overview: { - musters_closing_today: 'आज बंद हो रहे मस्टर्स', - delayed_musters: 'विलंबित मस्टर्स', - total_transactions: 'पिछले 3 महीनों में कुल कितने भुगतान हुए', - days_to_payment: 'पिछले 3 महीनों में भुगतान के लिए दिन', - cards_need_attention: 'कार्ड्स को आपके ध्यान की ज़रूरत है', - view_cards: 'कार्ड्स देखें' - }, - cards: { - musters_closing_today: 'आज बंद हो रहे मस्टर्स', - delayed_musters_1: 'विलंबित मस्टर्स', - muster_details: 'मस्टर्स की विस्तार से जानकारी', - current_musters: 'वर्तमान मस्टर्स', - delayed_musters_2: 'विलंबित मस्टर्स', - work_code: 'कार्य कोड', - work_name: 'कार्य नाम', - closure_date: 'मस्टर रोल बंद होने की तिथि', - days_delayed: 'विलंब(दिन)' - }, - chart: { - days_to_complete_process: 'प्रक्रिया पूरी करने में लगे दिन', - steps: { - 1:'मस्टर रोल बंद से डाटा एंट्री का समय', - 2:'डाटा एंट्री से वेज लिस्ट बनाने का समय', - 3:'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', - 4:'वेज लिस्ट भेजने से FTO बनाने का समय', - 5:'FTO बनाने से पहले हस्ताक्षर का समय', - 6:'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', - 7:'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय', - all:'पूरी प्रक्रिया के सारे पड़ाव', - }, - dates: { - all_dates: 'सभी तारीखें', - last_60: 'पिछले 60 दिन', - last_30: 'पिछले 30 दिन' - }, - regions: { - panchayat: 'पंचायत', - block: 'प्रखंड/जनपद' - }, - tooltip: { - date: 'तारीख', - days: 'औसत दिन', - transactions: 'भुगतान', - step: 'कदम' - } - }, - notifications: { - notifications: 'संदेश', - read: 'पठित', - unread: 'अपठित' - }, - profile: { - firstname: 'मूल नाम', - lastname: 'उपनाम', - profile: 'प्रोफ़ाइल', - account: 'अकाउंट', - work_email: 'औपचारिक e-mail', - mobile: 'मोबाइल नंबर', - personal_email: 'निजी e-mail', - lang : 'भाषा', - settings: 'सेट्टिंग्स', - logout: 'लौग आउट', - profile_settings: 'आपकी प्रोफ़ाइल सेट्टिंग्स', - email_settings: 'E-Mail सेट्टिंग्स', - primary_email_msg: 'आपके अकाउंट से संबंधित संदेशों और इंटरनेट-संबंधित प्रक्रियाओं के लिए आपके मुख्य e-mail ID का उपयोग किया जाएगा.', - save: 'अद्यतन (update)', - your_primary_email: 'आपका मुख्य e-mail ID', - change_pass: 'पासवर्ड बदलें', - old_pass: 'पुराना पासवर्ड ', - new_pass: 'नया पासवर्ड ', - pass_confirm:'नये पासवर्ड को सत्यापित करें', - forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया' - }, - messages: { - login: { - connectivity: 'हमे खेद है कि आप log in करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें |', - credentials: 'ऐसा व्यतीत होता है कि आपने ग़लत username या password भरा है | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |', - general: 'हमे खेद है कि आप log in करने में विफल रहे | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |' - }, - logout: { - connectivity: 'हमे खेद है कि आप log out करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें |', - warning: { - 'message':'क्या आप सचमुच Log Out करना चाहते हैं? PayDash का offline mode तभी तक उपलब्ध रहेगा जब तक आप logged in हैं |', - 'logout': 'Log out', - 'cancel': 'Cancel' - }, - general: 'हमे खेद है कि आप log out करने में विफल रहे | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |' - } - } - } -}; diff --git a/app/locales/hi/v1.js b/app/locales/hi/v1.js new file mode 100644 index 00000000..84c91a32 --- /dev/null +++ b/app/locales/hi/v1.js @@ -0,0 +1,222 @@ +'use strict'; + +module.exports = { + $meta: 'Hindi translation file', + web: { + navigation: { + overview: 'अवलोकन', + musters: { + $filter: 'role', + district: 'प्रखंड', + block: 'मस्टर्स' + }, + performance: 'प्रदर्शन' + }, + overview: { + current: 'वर्तमान मस्टर्स', + delayed: 'विलंबित मस्टर्स', + days_to_payment: 'भुगतान के लिए दिन', + welcome: { + 1: 'नमस्कार', + 2: 'जी' + }, + description: { + $filter : 'role', + block: 'MGNREGA भुगतनों के सन्दर्भ में आपके जनपद के प्रदर्शन से जुड़ी जानकारी प्रस्तुत है|', + district: 'MGNREGA भुगतनों के सन्दर्भ में आपके ज़िले के प्रदर्शन से जुड़ी जानकारी प्रस्तुत है' + } + }, + musters: { + current: 'वर्तमान मस्टर्स', + delayed: 'विलंबित मस्टर्स', + muster_details: 'मस्टर्स की विस्तार से जानकारी', + officers: 'OFFICERS', + delayed_musters: 'विलंबित मस्टर्स', + msr_no: 'MUSTER NO.', + panchayat_name: 'PANCHAYAT NAME', + work_name: 'कार्य नाम', + work_code: 'कार्य कोड', + closure_date: 'मस्टर रोल बंद होने की तिथि', + days_pending: 'DAYS PENDING', + current_total: 'वर्तमान मस्टर्स', + delayed_total: 'विलंबित मस्टर्स', + name: 'नाम', + designation: 'पदनाम', + block_name: 'प्रखंड नाम', + days_to_payment: 'भुगतान के दिन', + no_muster_information: 'इसमें कोई मस्टर जानकारी उपलब्ध है', + sort_by: 'क्रमबद्ध करें', + search_placeholder: 'खोजे' + }, + performance: { + overview: { + title: { + $filter: 'role', + district: 'आपके ज़िले का प्रदर्शन', + block: 'आपके प्रखंड/जनपद का प्रदर्शन', + $default: 'अवलोकन प्रदर्शन' + }, + description: { + $filter: 'role', + district: 'आपके ज़िले में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन', + block: 'आपके प्रखंड/जनपद में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन', + $default: 'आपके क्षेत्रों में मज़दूरी भुगतान के हर एक पड़ाव पर लगे औसत दिन' + }, + tooltip: 'यह ग्राफ़ MGNREGA मज़दूरी भुगतान में लगा औसत समय दिखाता है| वर्णित तिथियों पर हुए भुगतान में लगे समय को 7 पड़ावों में बाटा गया है| इसलिए, केवल पूरे हुए भुगतान का डाटा दिखाया जा रहा है|', + labels: [ + 'मस्टर रोल बंद से डाटा एंट्री का समय', + 'डाटा एंट्री से वेज लिस्ट बनाने का समय', + 'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', + 'वेज लिस्ट भेजने से FTO बनाने का समय', + 'FTO बनाने से पहले हस्ताक्षर का समय', + 'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', + 'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय' + ], + }, + comparison: { + title: { + $filter: 'role', + district: 'आपके प्रदर्शन की तुलना', + block: 'आपके प्रदर्शन की तुलना', + $default: 'आपके प्रदर्शन की तुलना' + }, + description: { + $filter: 'role', + district: 'अपने ज़िले के औसत प्रदर्शन की तुलना राज्य के औसत प्रदर्शन से करें', + block: 'अपने प्रखंड/जनपद के औसत प्रदर्शन की तुलना ज़िले और राज्य के औसत प्रदर्शन से करें ', + $default: 'अपने प्रखंड/जनपद के औसत प्रदर्शन की तुलना अन्य क्षेत्रों के औसत प्रदर्शन से करें' + }, + labels: { + 'state': 'राज्य औसत', + 'district': 'ज़िला औसत', + 'block': 'प्रखंड औसत', + 'panchayat': 'जनपद औसत', + }, + total_trans: { + 'state': 'Total state transactions in', + 'district': 'Total district transactions in', + 'block': 'Total block transactions in', + 'panchayat': 'Total panchayat transactions in', + }, + tooltip: 'यह ग्राफ़ MGNREGA मज़दूरी भुगतान में लगा औसत समय दिखाता है| वर्णित तिथियों पर हुए भुगतान में लगे समय को 7 पड़ावों में बाटा गया है| इसलिए, केवल पूरे हुए भुगतान का डाटा दिखाया जा रहा है|', + }, + y_axis_labels: 'प्रक्रिया पूरी करने में लगे दिन', + total_trans: 'तिथि : कुल भुगतानों की संख्या-' + }, + profile: { + firstname: 'मूल नाम', + lastname: 'उपनाम', + profile: 'प्रोफ़ाइल', + account: 'अकाउंट', + work_email: 'औपचारिक e-mail', + mobile: 'मोबाइल नंबर', + personal_email: 'निजी e-mail', + lang: 'भाषा', + settings: 'सेट्टिंग्स', + logout: 'लौग आउट', + profile_settings: 'आपकी प्रोफ़ाइल सेट्टिंग्स', + email_settings: 'E-Mail सेट्टिंग्स', + primary_email_msg: 'आपके अकाउंट से संबंधित संदेशों और इंटरनेट-संबंधित प्रक्रियाओं के लिए आपके मुख्य e-mail ID का उपयोग किया जाएगा.', + save: 'अद्यतन (update)', + your_primary_email: 'आपका मुख्य e-mail ID', + change_pass: 'पासवर्ड बदलें', + old_pass: 'पुराना पासवर्ड ', + new_pass: 'नया पासवर्ड ', + pass_confirm: 'नये पासवर्ड को सत्यापित करें', + forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया', + colorblind: 'रंग अंधा' + }, + }, + app: { + overview: { + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters: 'विलंबित मस्टर्स', + total_transactions: 'पिछले 3 महीनों में कुल कितने भुगतान हुए', + days_to_payment: 'पिछले 3 महीनों में भुगतान के लिए दिन', + cards_need_attention: 'कार्ड्स को आपके ध्यान की ज़रूरत है', + view_cards: 'कार्ड्स देखें' + }, + cards: { + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters_1: 'विलंबित मस्टर्स', + muster_details: 'मस्टर्स की विस्तार से जानकारी', + current_musters: 'वर्तमान मस्टर्स', + delayed_musters_2: 'विलंबित मस्टर्स', + work_code: 'कार्य कोड', + work_name: 'कार्य नाम', + closure_date: 'मस्टर रोल बंद होने की तिथि', + days_delayed: 'विलंब(दिन)' + }, + chart: { + days_to_complete_process: 'प्रक्रिया पूरी करने में लगे दिन', + steps: { + 1: 'मस्टर रोल बंद से डाटा एंट्री का समय', + 2: 'डाटा एंट्री से वेज लिस्ट बनाने का समय', + 3: 'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', + 4: 'वेज लिस्ट भेजने से FTO बनाने का समय', + 5: 'FTO बनाने से पहले हस्ताक्षर का समय', + 6: 'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', + 7: 'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय', + all: 'पूरी प्रक्रिया के सारे पड़ाव', + }, + dates: { + all_dates: 'सभी तारीखें', + last_60: 'पिछले 60 दिन', + last_30: 'पिछले 30 दिन' + }, + regions: { + panchayat: 'पंचायत', + block: 'प्रखंड/जनपद' + }, + tooltip: { + date: 'तारीख', + days: 'औसत दिन', + transactions: 'भुगतान', + step: 'कदम' + } + }, + notifications: { + notifications: 'संदेश', + read: 'पठित', + unread: 'अपठित' + }, + profile: { + firstname: 'मूल नाम', + lastname: 'उपनाम', + profile: 'प्रोफ़ाइल', + account: 'अकाउंट', + work_email: 'औपचारिक e-mail', + mobile: 'मोबाइल नंबर', + personal_email: 'निजी e-mail', + lang: 'भाषा', + settings: 'सेट्टिंग्स', + logout: 'लौग आउट', + profile_settings: 'आपकी प्रोफ़ाइल सेट्टिंग्स', + email_settings: 'E-Mail सेट्टिंग्स', + primary_email_msg: 'आपके अकाउंट से संबंधित संदेशों और इंटरनेट-संबंधित प्रक्रियाओं के लिए आपके मुख्य e-mail ID का उपयोग किया जाएगा.', + save: 'अद्यतन (update)', + your_primary_email: 'आपका मुख्य e-mail ID', + change_pass: 'पासवर्ड बदलें', + old_pass: 'पुराना पासवर्ड ', + new_pass: 'नया पासवर्ड ', + pass_confirm: 'नये पासवर्ड को सत्यापित करें', + forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया' + }, + messages: { + login: { + connectivity: 'हमे खेद है कि आप log in करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें |', + credentials: 'ऐसा व्यतीत होता है कि आपने ग़लत username या password भरा है | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |', + general: 'हमे खेद है कि आप log in करने में विफल रहे | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |' + }, + logout: { + connectivity: 'हमे खेद है कि आप log out करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें |', + warning: { + 'message': 'क्या आप सचमुच Log Out करना चाहते हैं? PayDash का offline mode तभी तक उपलब्ध रहेगा जब तक आप logged in हैं |', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'हमे खेद है कि आप log out करने में विफल रहे | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें |' + } + } + } +}; diff --git a/app/locales/hi/v2.js b/app/locales/hi/v2.js new file mode 100644 index 00000000..4df76f5c --- /dev/null +++ b/app/locales/hi/v2.js @@ -0,0 +1,276 @@ +'use strict'; + +module.exports = { + $meta: 'Hindi translation file', + app: { + $filter: 'role', + block: { + paydash: 'पे-डॅश', + overview: { + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters: 'विलंबित मस्टर्स', + total_transactions: 'पिछले 3 महीनों में कुल कितने भुगतान हुए', + days_to_payment: 'पिछले 3 महीनों में किए गये हर भुगतान में लगे औसत दिन', + cards_need_attention: 'कार्ड्स को आपके ध्यान की ज़रूरत है', + view_cards: 'कार्ड्स देखें' + }, + cards: { + cards: 'कार्ड्स', + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters_1: 'विलंबित मस्टर्स', + muster_details: 'मस्टर्स की विस्तार से जानकारी', + current_musters: 'वर्तमान मस्टर्स', + delayed_musters_2: 'विलंबित मस्टर्स', + work_code: 'कार्य कोड', + work_name: 'कार्य नाम', + closure_date: 'मस्टर रोल बंद होने की तिथि', + days_delayed: 'विलंब(दिन)', + step: 'कदम', + ds_t2: 'अटेंडेन्स नहीं भरी गयी (T+2)', + ds_t5: 'MB नहीं भरी गयी (T+5)', + ds_t6: 'वेज लिस्ट नहीं भेजी गयी (T+6)', + ds_t7: 'FTO पर पहला हस्ताक्षर नहीं हुआ (T+7)', + ds_t8: 'FTO पर दूसरा हस्ताक्षर नहीं हुआ (T+8)', + contact: { + phone: 'Phone', + whatsapp: 'WhatsApp' + } + }, + chart: { + days_to_complete_process: 'प्रक्रिया पूरी करने में लगे दिन', + steps: { + 1:'मस्टर रोल बंद से डाटा एंट्री का समय', + 2:'डाटा एंट्री से वेज लिस्ट बनाने का समय', + 3:'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', + 4:'वेज लिस्ट भेजने से FTO बनाने का समय', + 5:'FTO बनाने से पहले हस्ताक्षर का समय', + 6:'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', + 7:'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय', + total:'भुगतान प्रक्रिया पूरी करने में लगे दिन (बिना विभाजन के)', + all:'भुगतान प्रक्रिया पूरी करने में लगे दिन (पड़ावों में विभाजित)', + }, + statutory_limit: 'क़ानून द्वारा निर्धारित समया सीमा', + dates: { + all_dates: 'सभी तारीखें', + past_3_months: 'पिछले 3 महीने' + }, + regions: { + panchayat: 'पंचायत', + block: 'प्रखंड/जनपद', + }, + tooltip: { + date: 'तारीख', + days: 'औसत दिन', + transactions: 'भुगतान', + step: 'कदम' + } + }, + user_dropdown: { + profile: 'प्रोफ़ाइल', + logout: 'लौग आउट' + }, + profile: { + profile: 'प्रोफ़ाइल', + edit: 'प्रोफ़ाइल बदलें', + save:'प्रोफ़ाइल सेव करें', + updating:'अपडेट होने की प्रक्रिया जारी है...', + firstname: 'मूल नाम', + lastname: 'उपनाम', + mobile: 'मोबाइल नंबर', + personal_email: 'निजी e-mail', + work_email: 'औपचारिक e-mail', + colorblind: 'वर्णांधता (color blindness) के लिए अनुकूल रंग प्रणाली का उपयोग करें', + lang: 'भाषा', + eng: 'English', + hindi: 'Hindi', + change_pass_button: 'पासवर्ड बदलें' + }, + password: { + change_pass: 'पासवर्ड बदलें', + old_pass: 'पुराना पासवर्ड', + new_pass: 'नया पासवर्ड', + pass_confirm: 'नये पासवर्ड को सत्यापित करें', + forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया', + change_pass_button: 'पासवर्ड बदलें' + }, + search: 'उप यंत्री/ GRS का नाम खोजें', + sort: { + current_total: 'आज बंद हो रहे मस्टर्स', + delayed_total: 'विलंबित मस्टर्स', + name: 'नाम', + designation: 'पद' + }, + messages: { + login: { + connectivity: 'हमे खेद है कि आप log in करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें|', + credentials: 'ऐसा व्यतीत होता है कि आपने ग़लत username या password भरा है | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + general: 'हमे खेद है कि आप log in करने में विफल रहे| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + ga_account: 'इस मोबाइल/कंप्यूटर से जुड़ा Google अकाउंट आपके PayDash अकाउंट से जुड़े Google अकाउंट से अलग है| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + deactivated: 'आपका अकाउंट निष्क्रिय हो गया है| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|' + }, + logout: { + connectivity: 'हमे खेद है कि आप log out करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें|', + warning: { + 'message':'क्या आप सचमुच Log Out करना चाहते हैं? PayDash का offline mode तभी तक उपलब्ध रहेगा जब तक आप logged in हैं|', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'हमे खेद है कि आप log out करने में विफल रहे| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + logging_out: 'आप लोग आउट हो रहे हैं...' + }, + profile_success: 'आपकी प्रोफ़ाइल सफलतापूर्वक अपडेट हो चुकी है', + profile_error: 'प्रोफ़ाइल अपडेट करने की प्रक्रिया असफल रही| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + password_success: 'पासवर्ड सफलतापूर्वक बदला जा चुका है|', + password_wrong_old: 'पुराना पासवर्ड ग़लत है| सहयता के लिए PayDash दल से संपर्क करें|', + password_new_nomatch: 'नया पासवर्ड मेल नही ख़ाता|', + password_tooshort: 'आपके नये पासवर्ड की लंबाई कम से कम 6 अक्षर होनी चाहिए|', + password_network_error: 'पासवर्ड बदलने की प्रक्रिया असफल रही| कृपया नेटवर्क सशक्त होने पर दोबारा कोशिश करें|', + password_empty: 'पासवर्ड रिक्त नही रह सकता', + requesting_change: 'पासवर्ड बदलने की प्रक्रिया जारी है', + update_available: 'नया अपडेट उपलब्ध है', + update: 'अपडेट', + grant_permission: 'कृपया प्रक्रिया आगे बढ़ाने के लिए अनुमति दें' + }, + contact: { + contact: 'संपर्क करें', + gmail: 'Gmail', + phone: 'Phone' + }, + whatsapp: { + overview:'{name} के लिए मस्टर रोल विवरण\n\n{current_total} मस्टर रोल आज बंद हो रहे हैं\n{delayed_total} मस्टर रोल विलंबित हैं\n\n', + current:'आज बंद हो रहे मस्टर्स\n\n_मस्टर रोल क्रमांक_\n{msr_no}\n_पंचायत_\n{panchayat_name}\n_कार्य कोड_\n{work_code}\n_कार्य नाम_\n{work_name}\n_मस्टर रोल बंद होने की तिथि_\n{closure_date}\n\n', + delayed:'विलंबित मस्टर्स\n\n_मस्टर रोल क्रमांक_\n{msr_no}\n_पंचायत_\n{panchayat_name}\n_कार्य कोड_\n{work_code}\n_कार्य नाम_\n{work_name}\n_मस्टर रोल बंद होने की तिथि_\n{closure_date}\n_विलंब(दिन)_\n{days_pending}\n\n' + } + }, + district: { + paydash: 'पे-डॅश', + overview: { + view_your_blocks: 'अपने ज़िले के {blocks_total} जनपदों का प्रदर्शन देखें', + show_blocks: 'जनपद देखें', + days_to_payment: 'पिछले 3 महीनों में किए गये हर भुगतान में लगे औसत दिन', + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters: 'विलंबित मस्टर्स' + }, + cards: { + cards: 'कार्ड्स', + days_to_payment: 'पिछले 3 महीनों में किए गये हर भुगतान में लगे औसत दिन', + musters_closing_today: 'आज बंद हो रहे मस्टर्स', + delayed_musters: 'विलंबित मस्टर्स', + musters_diff_steps: 'विभिन्न पड़ावों पर विलंबित मस्टर रोल', + avg_days_pending: 'औसत विलंब', + total: 'कुल मस्टर रोल', + t_2: 'अटेंडेन्स नहीं भरी गयी (T+2)', + t_5: 'MB नहीं भरी गयी (T+5)', + t_6: 'वेज लिस्ट नहीं भेजी गयी (T+6)', + t_7: 'FTO पर पहला हस्ताक्षर नहीं हुआ (T+7)', + t_8: 'FTO पर दूसरा हस्ताक्षर नहीं हुआ (T+8)', + contact: { + phone: 'Phone', + whatsapp: 'WhatsApp' + } + }, + chart: { + days_to_complete_process: 'प्रक्रिया पूरी करने में लगे दिन', + steps: { + 1:'मस्टर रोल बंद से डाटा एंट्री का समय', + 2:'डाटा एंट्री से वेज लिस्ट बनाने का समय', + 3:'वेज लिस्ट बनाने से वेज लिस्ट भेजने का समय', + 4:'वेज लिस्ट भेजने से FTO बनाने का समय', + 5:'FTO बनाने से पहले हस्ताक्षर का समय', + 6:'पहले हस्ताक्षर से दूसरे हस्ताक्षर का समय', + 7:'दूसरे हस्ताक्षर से बैंक की कारवाई के समापन का समय', + total:'भुगतान प्रक्रिया पूरी करने में लगे दिन (बिना विभाजन के)', + all:'भुगतान प्रक्रिया पूरी करने में लगे दिन (पड़ावों में विभाजित)', + }, + statutory_limit: 'क़ानून द्वारा निर्धारित समया सीमा', + dates: { + all_dates: 'सभी तारीखें', + past_3_months: 'पिछले 3 महीने' + }, + regions: { + block: 'प्रखंड/जनपद', + district: 'ज़िला' + }, + tooltip: { + date: 'तारीख', + days: 'औसत दिन', + transactions: 'भुगतान', + step: 'कदम' + } + }, + user_dropdown: { + profile: 'प्रोफ़ाइल', + logout: 'लौग आउट' + }, + profile: { + profile: 'प्रोफ़ाइल', + edit: 'प्रोफ़ाइल बदलें', + save:'प्रोफ़ाइल सेव करें', + updating:'अपडेट होने की प्रक्रिया जारी है...', + firstname: 'मूल नाम', + lastname: 'उपनाम', + mobile: 'मोबाइल नंबर', + personal_email: 'निजी e-mail', + work_email: 'औपचारिक e-mail', + colorblind: 'वर्णांधता (color blindness) के लिए अनुकूल रंग प्रणाली का उपयोग करें', + lang: 'भाषा', + eng: 'English', + hindi: 'Hindi', + change_pass_button: 'पासवर्ड बदलें' + }, + password: { + change_pass: 'पासवर्ड बदलें', + old_pass: 'पुराना पासवर्ड', + new_pass: 'नया पासवर्ड', + pass_confirm: 'नये पासवर्ड को सत्यापित करें', + forgot_pass: 'मैं अपना पासवर्ड भूल गयी/गया', + change_pass_button: 'पासवर्ड बदलें' + }, + search: 'जनपद/प्रखंड या अफ़सर का नाम खोजें', + sort: { + current_total: 'आज बंद हो रहे मस्टर्स', + delayed_total: 'विलंबित मस्टर्स', + days_to_payment: 'पिछले 3 महीनों में किए गये हर भुगतान में लगे औसत दिन', + block_name: 'जनपद/प्रखंड का नाम', + ceo_name: 'जनपद/प्रखंड CEO का नाम' + }, + messages: { + login: { + connectivity: 'हमे खेद है कि आप log in करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें|', + credentials: 'ऐसा व्यतीत होता है कि आपने ग़लत username या password भरा है | यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + general: 'हमे खेद है कि आप log in करने में विफल रहे| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + ga_account: 'इस मोबाइल/कंप्यूटर से जुड़ा Google अकाउंट आपके PayDash अकाउंट से जुड़े Google अकाउंट से अलग है| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + deactivated: 'आपका अकाउंट निष्क्रिय हो गया है| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|' + }, + logout: { + connectivity: 'हमे खेद है कि आप log out करने में विफल रहे| कृपया अपने फ़ोन/कंप्यूटर की internet connectivity को जाँच लें|', + warning: { + 'message':'क्या आप सचमुच Log Out करना चाहते हैं? PayDash का offline mode तभी तक उपलब्ध रहेगा जब तक आप logged in हैं|', + 'logout': 'Log out', + 'cancel': 'Cancel' + }, + general: 'हमे खेद है कि आप log out करने में विफल रहे| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + logging_out: 'आप लोग आउट हो रहे हैं...' + }, + profile_success: 'आपकी प्रोफ़ाइल सफलतापूर्वक अपडेट हो चुकी है', + profile_error: 'प्रोफ़ाइल अपडेट करने की प्रक्रिया असफल रही| यदि यह समस्या कायम रहती है तो PayDash दल से संपर्क करें|', + password_success: 'पासवर्ड सफलतापूर्वक बदला जा चुका है|', + password_wrong_old: 'पुराना पासवर्ड ग़लत है| सहयता के लिए PayDash दल से संपर्क करें|', + password_new_nomatch: 'नया पासवर्ड मेल नही ख़ाता|', + password_tooshort: 'आपके नये पासवर्ड की लंबाई कम से कम 6 अक्षर होनी चाहिए|', + password_network_error: 'पासवर्ड बदलने की प्रक्रिया असफल रही| कृपया नेटवर्क सशक्त होने पर दोबारा कोशिश करें|', + password_empty: 'पासवर्ड रिक्त नही रह सकता', + requesting_change: 'पासवर्ड बदलने की प्रक्रिया जारी है', + update_available: 'नया अपडेट उपलब्ध है', + update: 'अपडेट', + grant_permission: 'कृपया प्रक्रिया आगे बढ़ाने के लिए अनुमति दें' + }, + contact: { + contact: 'संपर्क करें', + gmail: 'Gmail', + phone: 'Phone' + }, + whatsapp: '{name} के लए MGNREGA भुगतान प्रदर्शन\n\n_प्रखंड/जनपद_\n{block_name}\n\nभुगतान प्रक्रिया पूरी करने के लिए औसतन {days_to_payment} दिन लगे\n{current_total} मस्टर रोल आज बंद हो रहे हैं\n{delayed_total} मस्टर रोल विलंबित हैं\n\nविभिन्न पड़ावों पर विलंबित मस्टर रोल\n\n*अटेंडेन्स नहीं भरी गयी (T+2)*\n_कुल मस्टर रोल_\n{t2_total}\n_औसत विलंब_\n{t2_avg}\n\n*MB नहीं भरी गयी (T+5)*\n_कुल मस्टर रोल_\n{t5_total}\n_औसत विलंब_\n{t5_avg}\n\n*वेज लिस्ट नहीं भेजी गयी (T+6)*\n_कुल मस्टर रोल_\n{t6_total}\n_औसत विलंब_\n{t6_avg}\n\n*FTO पर पहला हस्ताक्षर नहीं हुआ (T+7)*\n_कुल मस्टर रोल_\n{t7_total}\n_औसत विलंब_\n{t7_avg}\n\n*FTO पर दूसरा हस्ताक्षर नहीं हुआ (T+8)*\n_कुल मस्टर रोल_\n{t8_total}\n_औसत विलंब_\n{t8_avg}\n' + } + } +}; diff --git a/app/models/feedbacks.js b/app/models/feedbacks.js deleted file mode 100644 index fe4518ba..00000000 --- a/app/models/feedbacks.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -module.exports = function(sequelize, DataTypes) { - var feedbacks = sequelize.define('feedbacks', { - msg: DataTypes.STRING, - region_code: DataTypes.STRING, - notification_id: DataTypes.INTEGER, - }, { - timestamps: true, - underscored: true, - classMethods: { - - associate: function(models) { - // associations can be defined here - feedbacks.belongsTo(models.User, { - onDelete: 'CASCADE', - foreignKey: 'user_id' - }); - } - } - }); - return feedbacks; -}; diff --git a/app/models/notifications.js b/app/models/notifications.js deleted file mode 100644 index 73e98787..00000000 --- a/app/models/notifications.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -module.exports = function(sequelize, DataTypes) { - var notifications = sequelize.define('notifications', { - msg: DataTypes.STRING, - region_code: DataTypes.STRING, - notification_type: DataTypes.INTEGER, - viewed: DataTypes.BOOLEAN, - batch_id: DataTypes.INTEGER, - region_name: DataTypes.STRING, - total_transactions: DataTypes.INTEGER, - days_to_payment: DataTypes.INTEGER, - batch_date: DataTypes.DATE - }, { - timestamps: true, - underscored: true, - classMethods: { - - associate: function(models) { - // associations can be defined here - notifications.belongsTo(models.User, { - onDelete: 'CASCADE', - foreignKey: 'user_id', - }); - } - } - }); - return notifications; -}; diff --git a/app/models/user.js b/app/models/user.js index 0f49186a..ff42567c 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,6 +1,7 @@ 'use strict'; module.exports = function(sequelize, DataTypes) { + var User = sequelize.define('User', { firstname: DataTypes.STRING, @@ -11,31 +12,28 @@ module.exports = function(sequelize, DataTypes) { }, password: DataTypes.STRING, role: DataTypes.STRING, - gender: DataTypes.STRING, - dob: DataTypes.STRING, mobile: DataTypes.STRING, email: DataTypes.STRING, - sas: DataTypes.BOOLEAN, - sas_years: DataTypes.STRING, - ias: DataTypes.BOOLEAN, - ias_years: DataTypes.STRING, title: DataTypes.STRING, - region_type: DataTypes.STRING, - region_name: DataTypes.STRING, work_email: DataTypes.STRING, - work_years: DataTypes.STRING, - time_on_nrega: DataTypes.STRING, isActive: DataTypes.BOOLEAN, - lang: DataTypes.STRING + lang: DataTypes.STRING, + designation: DataTypes.STRING, + phone_alternate : DataTypes.STRING, + middlename : DataTypes.STRING, + google_account: DataTypes.STRING, + type : DataTypes.STRING, + colorblind: DataTypes.BOOLEAN, + deactivated: DataTypes.BOOLEAN, + reset_password_token: DataTypes.STRING, + reset_password_expires: DataTypes.DATE }, { tableName: 'users', timestamps: true, underscored: true, classMethods: { associate: function(models) { - // associations can be defined here User.hasMany(models.user_regions); - User.hasMany(models.notifications); } } }); diff --git a/app/models/user_regions.js b/app/models/user_regions.js index a6e2f411..30d0bb6c 100644 --- a/app/models/user_regions.js +++ b/app/models/user_regions.js @@ -9,7 +9,7 @@ module.exports = function(sequelize, DataTypes) { underscored: true, classMethods: { associate: function(models) { - // associations can be defined here + user_blocks.belongsTo(models.User, { onDelete: 'CASCADE', foreignKey: 'user_id' diff --git a/app/routes/alerts.js b/app/routes/alerts.js deleted file mode 100644 index d49876de..00000000 --- a/app/routes/alerts.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -exports.register = function(plugin, options, next) { - plugin.dependency('auth', function(plugin, next) { - var Controllers = { - alerts: { - notifications: require('../controllers/alerts/notifications') - // feedbacks: require('../controllers/alerts/feedbacks') - } - }; - - plugin.route([ - - // Show Notifications - { - method: 'GET', - path: '/notifications/read', - config: Controllers.alerts.notifications.showReadNotifications - }, - // Show Notifications - { - method: 'GET', - path: '/notifications/unread', - config: Controllers.alerts.notifications.showUnreadNotifications - } - ]); - - next(); - }); - - next(); -}; - -exports.register.attributes = { - name: 'alert_routes', - version: require('../../package.json').version -}; diff --git a/app/routes/api.js b/app/routes/api.js index 2a866c97..31609f8b 100644 --- a/app/routes/api.js +++ b/app/routes/api.js @@ -1,57 +1,47 @@ 'use strict'; exports.register = function(plugin, options, next) { - // Load plugin dependencies - plugin.dependency(['auth'], function(plugin, next) { - var Controllers = { - api: { - login: require('../controllers/api/login'), - logout: require('../controllers/api/logout'), - cards: require('../controllers/api/cards'), - profile: require('../controllers/api/profile'), - translate: require('../controllers/api/translate'), - notifications: require('../controllers/api/notifications') - } - }; + const Controllers = { + api: { + login: require('../controllers/api/login'), + logout: require('../controllers/api/logout'), + account: require('../controllers/api/account'), + cards: require('../controllers/api/cards'), + profile: require('../controllers/api/profile'), + translate: require('../controllers/api/translate') + } + }; - plugin.route([ + plugin.route([ - // Api routes - { - method: 'POST', - path: '/api/login', - config: Controllers.api.login.postForm - }, { - method: 'POST', - path: '/api/profile', - config: Controllers.api.profile.postEditProfile - }, { - method: '*', - path: '/api/logout', - config: Controllers.api.logout.postForm - }, { - method: 'GET', - path: '/api/cards', - config: Controllers.api.cards.getData - }, { - method: 'GET', - path: '/api/translate', - config: Controllers.api.translate.getData - }, { - method: 'GET', - path: '/api/notifications/unread', - config: Controllers.api.notifications.showUnreadNotifications - }, - { - method: 'GET', - path: '/api/notifications/read', - config: Controllers.api.notifications.showReadNotifications - } - ]); - - next(); - }); + // Api routes + { + method: 'POST', + path: '/api/login', + config: Controllers.api.login.postForm + }, { + method: 'POST', + path: '/api/profile', + config: Controllers.api.profile.postEditProfile + }, { + method: '*', + path: '/api/logout', + config: Controllers.api.logout.postForm + },{ + method: 'POST', + path: '/api/password-change', + config: Controllers.api.account.postChangePassword + }, { + method: 'GET', + path: '/api/cards', + config: Controllers.api.cards.getData + }, { + method: 'GET', + path: '/api/translate', + config: Controllers.api.translate.getData + } + ]); next(); }; diff --git a/app/routes/auth.js b/app/routes/auth.js index eeb0dea1..b651c4be 100644 --- a/app/routes/auth.js +++ b/app/routes/auth.js @@ -1,36 +1,49 @@ 'use strict'; exports.register = function(plugin, options, next) { - // Load plugin dependencies - plugin.dependency(['auth', 'crumb'], function(plugin, next) { - var Controllers = { - auth: { - login: require('../controllers/auth/login'), - logout: require('../controllers/auth/logout') - } - }; + const Controllers = { + auth: { + login: require('../controllers/auth/login'), + logout: require('../controllers/auth/logout'), + forgotPassword: require('../controllers/auth/password-forgot'), + resetPassword: require('../controllers/auth/password-reset') + } + }; - plugin.route([ + plugin.route([ - // auth Routes - { - method: 'GET', - path: '/login', - config: Controllers.auth.login.showForm - }, { - method: 'POST', - path: '/login', - config: Controllers.auth.login.postForm - }, { - method: '*', - path: '/logout', - config: Controllers.auth.logout - } - ]); - - next(); - }); + // Auth Routes + { + method: 'GET', + path: '/login', + config: Controllers.auth.login.showForm + }, { + method: 'POST', + path: '/login', + config: Controllers.auth.login.postForm + }, { + method: '*', + path: '/logout', + config: Controllers.auth.logout + }, { + method: 'GET', + path: '/forgot-password', + config: Controllers.auth.forgotPassword.showRecoveryForm + }, { + method: 'POST', + path: '/forgot-password', + config: Controllers.auth.forgotPassword.postRecoveryForm + }, { + method: 'GET', + path: '/reset-password/{token}', + config: Controllers.auth.resetPassword.showResetForm + }, { + method: 'POST', + path: '/reset-password/{token}', + config: Controllers.auth.resetPassword.postResetForm + } + ]); next(); }; diff --git a/app/routes/contact.js b/app/routes/contact.js new file mode 100644 index 00000000..8bab0939 --- /dev/null +++ b/app/routes/contact.js @@ -0,0 +1,25 @@ +'use strict'; + +exports.register = function(plugin, options, next) { + + const Controllers = { + contact: require('../controllers/contact/contact') + }; + + plugin.route([ + + // Muster cards + { + method: 'GET', + path: '/contact', + config: Controllers.contact.getData + } + ]); + + next(); +}; + +exports.register.attributes = { + name: 'contact_routes', + version: require('../../package.json').version +}; diff --git a/app/routes/core.js b/app/routes/core.js index fb4dce7a..c30a17d5 100644 --- a/app/routes/core.js +++ b/app/routes/core.js @@ -2,79 +2,71 @@ exports.register = function(plugin, options, next) { - plugin.dependency('auth', function(plugin, next) { + const Controllers = { + core: { + pages: require('../controllers/core/pages'), + fallback: require('../controllers/core/fallback'), + static: require('../controllers/core/static') + } + }; - var Controllers = { - core: { - pages: require('../controllers/core/pages'), - fallback: require('../controllers/core/fallback'), - static: require('../controllers/core/static') - } - }; + plugin.route([ - plugin.route([ - - // Home Page - { - method: 'GET', - path: '/', - config: Controllers.core.pages.home + // Home Page + { + method: 'GET', + path: '/', + config: Controllers.core.pages.home + }, + // Assets & static Routes + { + method: 'GET', + path: '/css/{path*}', + config: { + auth: false }, - // Assets & static Routes - { - method: 'GET', - path: '/css/{path*}', - config: { - auth: false - }, - handler: Controllers.core.static.css - }, { - method: 'GET', - path: '/images/{path*}', - config: { - auth: false - }, - handler: Controllers.core.static.img - }, { - method: 'GET', - path: '/js/{path*}', - config: { - auth: false - }, - handler: Controllers.core.static.js - }, { - method: 'GET', - path: '/fonts/{path*}', - config: { - auth: false - }, - handler: Controllers.core.static.fonts - }, { - method: 'GET', - path: '/favicon.ico', - config: { - auth: false - }, - handler: Controllers.core.static.favicon - }, { - method: 'GET', - path: '/heartbeat', - config: Controllers.core.static.heartbeat + handler: Controllers.core.static.css + }, { + method: 'GET', + path: '/images/{path*}', + config: { + auth: false }, - // Fallback route - { - method: '*', - path: '/{p*}', - config: Controllers.core.fallback.notfound - } - - ]); - - next(); - }); - - + handler: Controllers.core.static.img + }, { + method: 'GET', + path: '/js/{path*}', + config: { + auth: false + }, + handler: Controllers.core.static.js + }, { + method: 'GET', + path: '/fonts/{path*}', + config: { + auth: false + }, + handler: Controllers.core.static.fonts + }, { + method: 'GET', + path: '/favicon.ico', + config: { + auth: false + }, + handler: Controllers.core.static.favicon + }, { + method: 'GET', + path: '/heartbeat', + config: Controllers.core.static.heartbeat + }, + // Fallback route + { + method: '*', + path: '/{p*}', + config: Controllers.core.fallback.notfound + } + ]); next(); }; diff --git a/app/routes/monitor.js b/app/routes/monitor.js deleted file mode 100644 index c3225231..00000000 --- a/app/routes/monitor.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -exports.register = function(plugin, options, next) { - - plugin.dependency('auth', function(plugin, next) { - - var Controllers = { - monitor: { - user: require('../controllers/monitor/user'), - server: require('../controllers/monitor/server'), - analysis: require('../controllers/monitor/analysis') - } - }; - - plugin.route([ - - // User monitororing dashbaord - { - method: 'GET', - path: '/monitor/user', - config: Controllers.monitor.user.showPage - }, - // User monitoring data - { - method: 'GET', - path: '/monitor/user/data', - config: Controllers.monitor.user.getData - }, - // Server monitoring - { - method: 'GET', - path: '/monitor/server', - config: Controllers.monitor.server.showPage - }, - // Server monitoring - { - method: 'GET', - path: '/monitor/server/data', - config: Controllers.monitor.server.getData - }, - // Server monitoring - { - method: 'GET', - path: '/monitor/server/pageloaddata', - config: Controllers.monitor.server.getPageLoadData - }, - // Analysis monitoring - { - method: 'GET', - path: '/monitor/analysis', - config: Controllers.monitor.analysis.showPage - }, - // Analysis monitoring data api - { - method: 'GET', - path: '/monitor/analysis/data', - config: Controllers.monitor.analysis.getData - } - ]); - - next(); - }); - - next(); -}; - -exports.register.attributes = { - name: 'monitor_routes', - version: require('../../package.json').version -}; diff --git a/app/routes/musters.js b/app/routes/musters.js index a71f5f37..257f83a1 100644 --- a/app/routes/musters.js +++ b/app/routes/musters.js @@ -2,45 +2,26 @@ exports.register = function(plugin, options, next) { - plugin.dependency('auth', function(plugin, next) { - - var Controllers = { - musters: { - current: require('../controllers/musters/current-musters'), - delayed: require('../controllers/musters/delayed-musters') - } - }; - - plugin.route([ - - // Block Dashoard - { - method: 'GET', - path: '/musters/current', - config: Controllers.musters.current.showPage - }, - // Block Dashoard - { - method: 'GET', - path: '/musters/current/data', - config: Controllers.musters.current.getData - }, - // Panchayat Dashboard - { - method: 'GET', - path: '/musters/delayed', - config: Controllers.musters.delayed.showPage - }, - // Block Dashoard - { - method: 'GET', - path: '/musters/delayed/data', - config: Controllers.musters.delayed.getData - }, - ]); - - next(); - }); + const Controllers = { + musters: require('../controllers/musters/musters') + }; + + plugin.route([ + + // Muster cards + { + method: 'GET', + path: '/musters', + config: Controllers.musters.showPage + }, + + // Muster cards data + { + method: 'GET', + path: '/musters/data', + config: Controllers.musters.getData + }, + ]); next(); }; diff --git a/app/routes/overview.js b/app/routes/overview.js new file mode 100644 index 00000000..f5221056 --- /dev/null +++ b/app/routes/overview.js @@ -0,0 +1,32 @@ +'use strict'; + +exports.register = function(plugin, options, next) { + + const Controllers = { + overview: require('../controllers/overview/overview') + }; + + plugin.route([ + + // Overview + { + method: 'GET', + path: '/overview', + config: Controllers.overview.showPage + }, + + // Overview data + { + method: 'GET', + path: '/overview/data', + config: Controllers.overview.getData + } + ]); + + next(); +}; + +exports.register.attributes = { + name: 'overview_routes', + version: require('../../package.json').version +}; diff --git a/app/routes/performance.js b/app/routes/performance.js index 3efda168..65f70065 100644 --- a/app/routes/performance.js +++ b/app/routes/performance.js @@ -2,47 +2,26 @@ exports.register = function(plugin, options, next) { - plugin.dependency('auth', function(plugin, next) { - - var Controllers = { - performance: { - overview: require('../controllers/performance/overview'), - discrete: require('../controllers/performance/discrete'), - panchayat: require('../controllers/performance/panchayat') - } - }; - - plugin.route([ - - // Overview Performance - { - method: 'GET', - path: '/performance/overview', - config: Controllers.performance.overview.showPage - }, { - method: 'GET', - path: '/performance/overview/data', - config: Controllers.performance.overview.getData - }, - // Discrete Performance - { - method: 'GET', - path: '/performance/discrete', - config: Controllers.performance.discrete.showPage - }, { - method: 'GET', - path: '/performance/discrete/data', - config: Controllers.performance.discrete.getData - }, - { - method: 'GET', - path: '/performance/panchayat/data', - config: Controllers.performance.panchayat.getData - } - ]); - - next(); - }); + const Controllers = { + performance: require('../controllers/performance/performance') + }; + + plugin.route([ + + // Performance + { + method: 'GET', + path: '/performance', + config: Controllers.performance.showPage + }, + + // Performance data + { + method: 'GET', + path: '/performance/data', + config: Controllers.performance.getData + } + ]); next(); }; diff --git a/app/routes/users.js b/app/routes/users.js index 39c9913a..c0757bce 100644 --- a/app/routes/users.js +++ b/app/routes/users.js @@ -2,45 +2,40 @@ exports.register = function(plugin, options, next) { - plugin.dependency('auth', function(plugin, next) { - - var Controllers = { - settings: { - profile: require('../controllers/users/settings-profile'), - account: require('../controllers/users/settings-account') - } - }; - - plugin.route([ - - // Settings - Show Edit profile - { - method: 'GET', - path: '/me/settings/profile', - config: Controllers.settings.profile.showEditProfile - }, - // Settings - Post Edit profile - { - method: 'POST', - path: '/me/settings/profile', - config: Controllers.settings.profile.postEditProfile - }, - // Settings - Show Edit account - { - method: 'GET', - path: '/me/settings/account', - config: Controllers.settings.account.showEditAccount - }, - // Settings - Post Edit account for change password - { - method: 'POST', - path: '/me/settings/account/change-password', - config: Controllers.settings.account.postChangePassword - } - ]); - - next(); - }); + const Controllers = { + settings: { + profile: require('../controllers/users/settings-profile'), + account: require('../controllers/users/settings-account') + } + }; + + plugin.route([ + + // Settings - Show Edit profile + { + method: 'GET', + path: '/me/settings/profile', + config: Controllers.settings.profile.showEditProfile + }, + // Settings - Post Edit profile + { + method: 'POST', + path: '/me/settings/profile', + config: Controllers.settings.profile.postEditProfile + }, + // Settings - Show Edit account + { + method: 'GET', + path: '/me/settings/account', + config: Controllers.settings.account.showEditAccount + }, + // Settings - Post Edit account for change password + { + method: 'POST', + path: '/me/settings/account/change-password', + config: Controllers.settings.account.postChangePassword + } + ]); next(); }; diff --git a/app/templates/alerts/notifications-read.hbs b/app/templates/alerts/notifications-read.hbs deleted file mode 100644 index a6e715a3..00000000 --- a/app/templates/alerts/notifications-read.hbs +++ /dev/null @@ -1,18 +0,0 @@ -
- - -
-{{> footer}} diff --git a/app/templates/alerts/notifications-unread.hbs b/app/templates/alerts/notifications-unread.hbs deleted file mode 100644 index 949d15e9..00000000 --- a/app/templates/alerts/notifications-unread.hbs +++ /dev/null @@ -1,19 +0,0 @@ -
- -
-{{> footer}} diff --git a/app/templates/auth/login.hbs b/app/templates/auth/login.hbs index 59b99fd4..61e0cd55 100644 --- a/app/templates/auth/login.hbs +++ b/app/templates/auth/login.hbs @@ -8,6 +8,7 @@ + I forgot my password {{> form_security}} diff --git a/app/templates/auth/password-recovery.hbs b/app/templates/auth/password-recovery.hbs new file mode 100644 index 00000000..82d27c05 --- /dev/null +++ b/app/templates/auth/password-recovery.hbs @@ -0,0 +1,13 @@ +
+ +

To reset your password, enter your username or registered email address.

+
+ {{> flash}} + +
+
diff --git a/app/templates/auth/password-reset.hbs b/app/templates/auth/password-reset.hbs new file mode 100644 index 00000000..3343c98f --- /dev/null +++ b/app/templates/auth/password-reset.hbs @@ -0,0 +1,20 @@ +
+ +

Reset your password

+ {{#if isValidToken}} +
+ {{> flash}} +
+ + + + + + {{> form_security}} +
+
+ {{else}} +

Token Invalid

+

Your password reset token is invalid. Try generating a new one.

+ {{/if}} +
diff --git a/app/templates/contact/contact.hbs b/app/templates/contact/contact.hbs new file mode 100644 index 00000000..4a597bff --- /dev/null +++ b/app/templates/contact/contact.hbs @@ -0,0 +1,9 @@ +
+

Contact PayDash team

+
+ Email Us +
+
+
Or
+
Call us at {{info.phone}}
+
diff --git a/app/templates/emails/forgot-password.hbs b/app/templates/emails/forgot-password.hbs new file mode 100644 index 00000000..1fb250a3 --- /dev/null +++ b/app/templates/emails/forgot-password.hbs @@ -0,0 +1,6 @@ +

Forgot Password

+

Hi {{name}}

+

+ Please follow this link to reset your password. +

+

{{url}}

diff --git a/app/templates/emails/verify-email.hbs b/app/templates/emails/verify-email.hbs new file mode 100644 index 00000000..d9b0c761 --- /dev/null +++ b/app/templates/emails/verify-email.hbs @@ -0,0 +1,6 @@ +

Verify email

+

Hi {{name}}

+

+ Please follow this link to verify your email. +

+

{{url}}

diff --git a/app/templates/helpers/m.js b/app/templates/helpers/m.js deleted file mode 100644 index 1ef97323..00000000 --- a/app/templates/helpers/m.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; -var manifest = require('../../../public/rev-manifest.json'); -module.exports = function(filename) { - return manifest[filename]; -}; diff --git a/app/templates/helpers/t.js b/app/templates/helpers/t.js index d0b3a47a..9ba7a948 100644 --- a/app/templates/helpers/t.js +++ b/app/templates/helpers/t.js @@ -2,20 +2,31 @@ var Confidence = require('confidence'); var locales = { - en_US: require('../../locales/en_US/index'), - hi: require('../../locales/hi/index') + en_US: { + v1: require('../../locales/en_US/v1'), + v2: require('../../locales/en_US/v2') + }, + hi: { + v1: require('../../locales/hi/v1'), + v2: require('../../locales/hi/v2') + } }; -module.exports = function t(path, credentials) { +module.exports = function t(path, credentials, version) { var lang = 'hi'; var criteria = {}; - + var ver; + if (version) { + ver = 'v' + version; + } else { + ver = 'v1'; + } if (credentials) { criteria.role = credentials.role; lang = credentials.lang; } - var store = new Confidence.Store(locales[lang]); + var store = new Confidence.Store(locales[lang][ver]); return store.get(path, criteria); }; diff --git a/app/templates/homepage.hbs b/app/templates/homepage.hbs index 4629ba11..504d7249 100644 --- a/app/templates/homepage.hbs +++ b/app/templates/homepage.hbs @@ -1,7 +1,9 @@
- +

MGNREGA

Worker Payments Dashboard

Get started
diff --git a/app/templates/layouts/default.hbs b/app/templates/layouts/default.hbs index 5d3b2885..3989cff5 100644 --- a/app/templates/layouts/default.hbs +++ b/app/templates/layouts/default.hbs @@ -2,17 +2,7 @@ - - {{#if title}}{{title}} - {{#if q}}{{q}}{{/if}}{{else}}PayDash{{/if}} - - {{#if package}} - - - - - - {{/if}} + PayDash diff --git a/app/templates/layouts/monitor.hbs b/app/templates/layouts/monitor.hbs deleted file mode 100644 index b09da611..00000000 --- a/app/templates/layouts/monitor.hbs +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - {{#if title}}{{title}} - {{#if q}}{{q}}{{/if}}{{else}}PayDash{{/if}} - - {{#if package}} - - - - - - {{/if}} - - - - - - - - - - - - - {{> monitor_header}} - {{{ content }}} - - - - - - diff --git a/app/templates/monitor/analysis.hbs b/app/templates/monitor/analysis.hbs deleted file mode 100644 index 6d700752..00000000 --- a/app/templates/monitor/analysis.hbs +++ /dev/null @@ -1,8 +0,0 @@ -
- -
-
-
diff --git a/app/templates/monitor/server.hbs b/app/templates/monitor/server.hbs deleted file mode 100644 index f5be0c2f..00000000 --- a/app/templates/monitor/server.hbs +++ /dev/null @@ -1,38 +0,0 @@ -
- {{!-- CPU Use chart --}} -
CPU usages
-
-
-
-
-
-
-
- {{!-- CPU Use chart --}} -
Memory usages
-
-
-
-
-
-
-
- {{!-- Heap Use chart --}} -
Heap usages
-
-
-
-
-
-
-
- {{!-- Heap Use chart --}} -
Page Timing Chart
-
-
-
-
-
-
-
-
diff --git a/app/templates/monitor/user.hbs b/app/templates/monitor/user.hbs deleted file mode 100644 index 7ed649be..00000000 --- a/app/templates/monitor/user.hbs +++ /dev/null @@ -1,47 +0,0 @@ -
- {{!-- Number of Sessions chart --}} -
User sessions
-
-
-
-
-
-
-
- {{!-- Session duration chart --}} -
Session duration
-
-
-
-
-
-
-
- {{!-- Time spent per page chart --}} -
Time spent
-
-
-
-
-
-
-
- {{!-- Time spent per page chart --}} -
Unique users
-
-
-
-
-
-
-
- {{!-- Time spent per page chart --}} -
Sessions per user
-
-
-
-
-
-
-
-
diff --git a/app/templates/musters/current.hbs b/app/templates/musters/current.hbs deleted file mode 100644 index d3f64ab7..00000000 --- a/app/templates/musters/current.hbs +++ /dev/null @@ -1,24 +0,0 @@ -
- {{>loader}} -
-

{{t "/musters/current/title" credentials}}

- {{!-- Mapping message --}} -
-
    -
  • {{t "/performance/discrete/grs_message" credentials}}
  • -
-
- - - - - - - - - - -
Msr noWorkPanchayatGRSMobile
-
- {{> footer}} -
diff --git a/app/templates/musters/delayed.hbs b/app/templates/musters/delayed.hbs deleted file mode 100644 index 0f10bbff..00000000 --- a/app/templates/musters/delayed.hbs +++ /dev/null @@ -1,84 +0,0 @@ -
- {{>loader}} -
-

{{t "/musters/delayed/title" credentials}}

- {{!-- Mapping message --}} -
-
    -
  • {{t "/performance/discrete/grs_message" credentials}}
  • -
  • {{t "/performance/discrete/ta_message" credentials}}
  • -
-
-
-

{{t "/musters/delayed/t_2" credentials}}

- - - - - - - - - - - - -
Msr NoWorkPanchayatClosure dateDays pendingGRS nameMobile
-
-

{{t "/musters/delayed/t_5" credentials}}

- - - - - - - - - - - - -
Msr NoWorkPanchayatClosure dateDays pendingTA NameMobile
-
-

{{t "/musters/delayed/t_6" credentials}}

- - - - - - - - - - -
Msr NoWorkPanchayatClosure dateDays pending
-
-

{{t "/musters/delayed/t_7" credentials}}

- - - - - - - - - - -
Msr NoWorkPanchayatClosure dateDays pending
-
-

{{t "/musters/delayed/t_8" credentials}}

- - - - - - - - - - -
Msr NoWorkPanchayatClosure dateDays pending
-
- {{> footer}} -
- diff --git a/app/templates/musters/musters.hbs b/app/templates/musters/musters.hbs new file mode 100644 index 00000000..4b4725ae --- /dev/null +++ b/app/templates/musters/musters.hbs @@ -0,0 +1,3 @@ +
+
+
diff --git a/app/templates/overview/overview.hbs b/app/templates/overview/overview.hbs new file mode 100644 index 00000000..199353cd --- /dev/null +++ b/app/templates/overview/overview.hbs @@ -0,0 +1,13 @@ +
+
+
+
+ {{t "/web/overview/welcome/1" credentials null}} {{credentials.firstname}} {{credentials.lastname}} {{t "/web/overview/welcome/2" credentials null}} +
+

{{t "/web/overview/description" credentials null}}

+
+
+
+
+
+
diff --git a/app/templates/partials/ga.hbs b/app/templates/partials/ga.hbs index 873ca3f3..18225343 100644 --- a/app/templates/partials/ga.hbs +++ b/app/templates/partials/ga.hbs @@ -9,8 +9,6 @@ ga('create', 'UA-54269439-4', 'auto'); ga('set', 'userId', {{credentials.id}}); // Set the user ID using signed-in user_id. ga('set', 'dimension1', {{credentials.id}}); - - ga('set', 'dimension2', '170002'); // Set user block as dimension {{else}} ga('create', 'UA-54269439-4', 'auto'); {{/if}} diff --git a/app/templates/partials/header.hbs b/app/templates/partials/header.hbs index ae892335..887c8190 100644 --- a/app/templates/partials/header.hbs +++ b/app/templates/partials/header.hbs @@ -1,41 +1,24 @@
Paydash - {{#if credentials}}
- - - - -
-
{{t "/profile/profile_settings" credentials}}
{{> flash}} -

{{t "/profile/firstname" credentials}} : {{user.firstname}}

-

{{t "/profile/lastname" credentials}} : {{user.lastname}}

+
{{t "/web/profile/profile_settings" credentials null}}
+ {{> flash}} +

{{t "/web/profile/firstname" credentials null}} : {{user.firstname}}

+

{{t "/web/profile/lastname" credentials null}} : {{user.lastname}}

- + - + - + - + + + {{> form_security}} - +
diff --git a/assets/images/grid.png b/assets/images/grid.png deleted file mode 100644 index afdfa3e1..00000000 Binary files a/assets/images/grid.png and /dev/null differ diff --git a/assets/images/logo.jpeg b/assets/images/logo.jpeg new file mode 100644 index 00000000..25b13aa9 Binary files /dev/null and b/assets/images/logo.jpeg differ diff --git a/assets/images/logo.png b/assets/images/logo.png new file mode 100644 index 00000000..26260c3b Binary files /dev/null and b/assets/images/logo.png differ diff --git a/assets/images/settings.png b/assets/images/settings.png deleted file mode 100644 index 2650b2cf..00000000 Binary files a/assets/images/settings.png and /dev/null differ diff --git a/assets/misc/favicon.ico b/assets/misc/favicon.ico deleted file mode 100644 index 9e0d4eef..00000000 Binary files a/assets/misc/favicon.ico and /dev/null differ diff --git a/assets/scripts/components/active-link.js b/assets/scripts/components/active-link.js deleted file mode 100644 index 5fe0d70f..00000000 --- a/assets/scripts/components/active-link.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; -var $ = require('jquery'); -var d3 = require('d3'); - -$('a[href="' + location.pathname + '"]').addClass('active'); - -// MENU -d3.selectAll('#top-ham').on('click', function() { - d3.selectAll('#top-ham').classed('active', function(d, i) { - return !d3.select(this).classed('active'); - }); - d3.selectAll('.menu-wrapper').classed('active', function(d, i) { - return !d3.select(this).classed('active'); - }); -}); diff --git a/assets/scripts/components/global/loader.jsx b/assets/scripts/components/global/loader.jsx new file mode 100644 index 00000000..8128f604 --- /dev/null +++ b/assets/scripts/components/global/loader.jsx @@ -0,0 +1,22 @@ +'use strict'; + +import React from 'react'; + +const Loader = React.createClass({ + + render: function(){ + + var divStyle = { + display: this.props.loading ? 'block' : 'none' + }; + + return ( +
+
Loading...
+
Loading data...
+
+ ); + } +}); + +export default Loader; diff --git a/assets/scripts/components/global/modal.jsx b/assets/scripts/components/global/modal.jsx new file mode 100644 index 00000000..a6da8023 --- /dev/null +++ b/assets/scripts/components/global/modal.jsx @@ -0,0 +1,28 @@ +'use strict'; + +import React from 'react'; +import {render} from 'react-dom'; + +const Modal = React.createClass({ + + render() { + + const styles = { + modal: { + display : (this.props.show) ? null : 'none' + } + }; + + return ( +
+
+ + { this.props.children } +
+
+ ); + } + +}); + +export default Modal; diff --git a/assets/scripts/components/musters/block-card.jsx b/assets/scripts/components/musters/block-card.jsx new file mode 100644 index 00000000..81548f77 --- /dev/null +++ b/assets/scripts/components/musters/block-card.jsx @@ -0,0 +1,61 @@ +'use strict'; + +import React from 'react'; +import Modal from '../global/modal.jsx'; +import Table from './table.jsx'; + +const BlockCard = React.createClass({ + + toggleModal() { + const state = this.state.modalOpen; + this.setState({ modalOpen: !state}); + ga('send', 'event', { + eventCategory: 'Block Muster detail', + eventAction: 'click', + eventLabel: this.props.data.staff_id + '/' + this.props.key + }); + }, + getInitialState: function(){ + return { + modalOpen: false + }; + }, + render: function(){ + + if(this.props.data.delayed_musters.length>0){ + var delayed_table =
; + } + if(this.props.data.current_musters.length>0){ + var current_table =
; + } + return ( +
+
+
+
{this.props.data.name}
+
{this.props.data.designation}
+
{this.props.data.mobile}
+
+
+
+
{this.props.translation.current}
+
{this.props.data.current_total}
+
+
+
{this.props.translation.delayed}
+
{this.props.data.delayed_total}
+
+
+ + +
+
+
+
+
+ ); + } +}); + + +export default BlockCard; diff --git a/assets/scripts/components/musters/block-group.jsx b/assets/scripts/components/musters/block-group.jsx new file mode 100644 index 00000000..3ff15585 --- /dev/null +++ b/assets/scripts/components/musters/block-group.jsx @@ -0,0 +1,75 @@ +'use strict'; + +import React from 'react'; +import BlockCard from './block-card.jsx'; +import Sort from './sort.jsx'; + +const BlockGroup = React.createClass({ + + filterCards: function(event){ + + var updatedList = this.props.data.cards; + updatedList = updatedList.filter(function(item){ + return item.name.toLowerCase().search(event.target.value.toLowerCase()) !== -1; + }); + this.setState({cards: updatedList}); + }, + sortBy(field){ + + var updatedList = this.props.data.cards.slice(0); + + updatedList.sort(function (a, b) { + if(typeof(a[field]) === 'number'){ + + if (a[field] > b[field]) {return -1;} + if (a[field] < b[field]) {return 1;} + if (a.name.toLowerCase() < b.name.toLowerCase()) {return -1;} + if (a.name.toLowerCase() > b.name.toLowerCase()) {return 1;} + return 0; + + } else if(typeof(a[field]) === 'string'){ + if (a[field].toLowerCase() > b[field].toLowerCase()) {return 1;} + if (a[field].toLowerCase() < b[field].toLowerCase()) {return -1;} + if (field!=='name') { + if (a.name.toLowerCase() < b.name.toLowerCase()) {return -1;} + if (a.name.toLowerCase() > b.name.toLowerCase()) {return 1;} + } + return 0; + } + }); + this.setState({cards: updatedList}); + }, + getInitialState: function(){ + return { + cards: [] + }; + }, + componentWillMount: function(){ + this.setState({cards: this.props.data.cards}); + }, + render: function(){ + + var _this = this; + var sortList = ['name', 'designation', 'current_total', 'delayed_total']; + + return ( +
+
+ + +

{this.props.data.region_name}

+
+
+ { + this.state.cards.map(function(data, i) { + return ; + }) + } +
+
+ ); + } +}); + + +export default BlockGroup; diff --git a/assets/scripts/components/musters/district-card.jsx b/assets/scripts/components/musters/district-card.jsx new file mode 100644 index 00000000..351d82d6 --- /dev/null +++ b/assets/scripts/components/musters/district-card.jsx @@ -0,0 +1,110 @@ +'use strict'; + +import React from 'react'; +import Modal from '../global/modal.jsx'; +import Table from './table.jsx'; + +const DistrictCard = React.createClass({ + + toggleModal() { + const state = this.state.modalOpen; + this.setState({ modalOpen: !state}); + ga('send', 'event', { + eventCategory: 'District Muster detail', + eventAction: 'click', + eventLabel: this.props.data.block_code + '/' + this.props.key + }); + }, + getInitialState: function(){ + return { + modalOpen: false + }; + }, + render: function(){ + return ( + + + +
+
+
+
{this.props.data.block_name}
+
+
+
+
{this.props.translation.days_to_payment}
+
{this.props.data.days_to_payment}
+
+
+
+
+
{this.props.translation.current}
+
{this.props.data.current_total}
+
+
+
{this.props.translation.delayed}
+
{this.props.data.delayed_total}
+
+
+ { + this.props.data.officers.map(function(officer, i) { + return ( +
+
{officer.name}
+
+ {officer.designation} + {officer.mobile} +
+
+ ); + }) + } + + +

MUSTER DETAILS

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
StepTotal delayed mustersAverage days delayed
Attendance not filled (T+2){this.props.data.t2_total}{this.props.data.t2_avg}
Measurement book not filled (T+5){this.props.data.t5_total}{this.props.data.t5_avg}
Wagelist not sent (T+6){this.props.data.t6_total}{this.props.data.t6_avg}
Pending for FTO first signature (T+7){this.props.data.t7_total}{this.props.data.t7_avg}
Pending for FTO second signature (T+8){this.props.data.t8_total}{this.props.data.t8_avg}
+
+
+
+ ); + } +}); + + +export default DistrictCard; diff --git a/assets/scripts/components/musters/district-group.jsx b/assets/scripts/components/musters/district-group.jsx new file mode 100644 index 00000000..0fe77e57 --- /dev/null +++ b/assets/scripts/components/musters/district-group.jsx @@ -0,0 +1,91 @@ +'use strict'; + +import React from 'react'; +import DistrictCard from './district-card.jsx'; +import Sort from './sort.jsx'; + +const BlockGroup = React.createClass({ + + filterCards: function(event){ + + var updatedList = this.props.data.cards; + updatedList = updatedList.filter(function(item){ + + var match = false; + + if(item.block_name.toLowerCase().search(event.target.value.toLowerCase()) !== -1){ + match = true; + } + + item.officers.forEach(function(officer){ + if(officer.name.toLowerCase().search(event.target.value.toLowerCase()) !== -1){ + match = true; + } + }); + + return match; + }); + this.setState({cards: updatedList}); + }, + sortBy(field){ + + var updatedList = this.props.data.cards.slice(0); + + updatedList.sort(function (a, b) { + if(typeof(a[field]) === 'number'){ + + if(a[field] > b[field]){ + return -1; + } else if (a[field] < b[field]){ + return 1; + } else{ + return 0; + } + + } else if(typeof(a[field]) === 'string'){ + if(a[field].toLowerCase() > b[field].toLowerCase()){ + return 1; + } else if (a[field].toLowerCase() < b[field].toLowerCase()){ + return -1; + } else{ + return 0; + } + } + }); + + this.setState({cards: updatedList}); + }, + getInitialState: function(){ + return { + cards: [] + }; + }, + componentWillMount: function(){ + this.setState({cards: this.props.data.cards}); + }, + render: function(){ + + var _this = this; + var sortList = ['block_name', 'current_total', 'delayed_total', 'days_to_payment']; + + return ( +
+
+ + +

{_this.props.data.region_name}

+
+
+ { + _this.state.cards.map(function(data, i) { + return ; + }) + } +
+
+ ); + } +}); + + +export default BlockGroup; diff --git a/assets/scripts/components/musters/sort.jsx b/assets/scripts/components/musters/sort.jsx new file mode 100644 index 00000000..12fcee28 --- /dev/null +++ b/assets/scripts/components/musters/sort.jsx @@ -0,0 +1,30 @@ +'use strict'; + +import React from 'react'; + +const Sort = React.createClass({ + sort(event){ + this.props.sortBy(event.target.value); + + ga('send', 'event', { + eventCategory: 'Sort Dropdown', + eventAction: 'selected', + eventLabel: this.props.translation[event.target.value] + }); + }, + render: function(){ + var _this = this; + return ( + + ); + } +}); + +export default Sort; diff --git a/assets/scripts/components/musters/table.jsx b/assets/scripts/components/musters/table.jsx new file mode 100644 index 00000000..fd13e53b --- /dev/null +++ b/assets/scripts/components/musters/table.jsx @@ -0,0 +1,52 @@ +'use strict'; + +import React from 'react'; + +const Table = React.createClass({ + + render: function(){ + + var _this = this; + var table; + + if(_this.props.data.length>0){ + table = ( + + + { + _this.props.data.length > 0 && Object.keys(_this.props.data[0]).map(function(key){ + return ; + }) + } + + + + { + _this.props.data.map(function(data, i) { + return ( + + { + Object.keys(data).map(function(key, i) { + return ; + }) + } + + ); + }) + } + +
{_this.props.translation[key]}
{data[key]}
); + } else{ + table =

{_this.props.translation.no_muster_information}

; + } + + return ( +
+

{_this.props.title}

+ {table} +
+ ); + } +}); + +export default Table; diff --git a/assets/scripts/components/overview/tile.jsx b/assets/scripts/components/overview/tile.jsx new file mode 100644 index 00000000..3c00feab --- /dev/null +++ b/assets/scripts/components/overview/tile.jsx @@ -0,0 +1,31 @@ +'use strict'; + +import React from 'react'; + +const Tile = React.createClass({ + + render: function(){ + return ( +
+
{this.props.data.region_name}
+
+
+
{this.props.translation.current}
+
{this.props.data.current_total}
+
+
+
{this.props.translation.delayed}
+
{this.props.data.delayed_total}
+
+
+
{this.props.translation.days_to_payment}
+
{this.props.data.days_to_payment}
+
+
+
+ ); + } +}); + + +export default Tile; diff --git a/assets/scripts/components/performance/comparison-chart.jsx b/assets/scripts/components/performance/comparison-chart.jsx new file mode 100644 index 00000000..c6562171 --- /dev/null +++ b/assets/scripts/components/performance/comparison-chart.jsx @@ -0,0 +1,215 @@ +'use strict'; + +import React from 'react'; +import MG from '../../lib/mg'; + +const D3 = require('d3'); +const Parser = require('../../lib/parser'); +const Region = require('../../lib/region'); + +const ComparisonChart = React.createClass({ + + getInitialState: function(){ + return { + active_step: 1, + active_lines: [], + comparison_lines:[] + }; + }, + loadChart: function(){ + + var _this = this; + var c_data = []; + var legend_target = '.comparison_legend'; + var labels = []; + + if(!_this.props.activeRegion) { + return; + } + + _this.state.active_lines.forEach(function(comparison_line, index) { + + var region = Region.find(_this.props.config.role, _this.props.activeRegion, _this.props.performance, comparison_line); + + labels.push(region[comparison_line + '_name'] + ' ' + _this.props.translation.comparison.labels[comparison_line]); + + var line_data = Parser.lines({ + data: region.data, + col: [_this.state.active_step], + isCumulative: false + }); + if (line_data[0]) { + c_data.push(line_data[0]); // Workaround to append region data + } + }); + + MG.data_graphic({ + title: '', + target: _this.elem, + data: c_data, + width: 600, + height: 500, + left: 100, + full_width: true, + decimals: 0, + xax_count: 10, + // max_x : options.max_x || null, + // min_x: options.min_x || null, + xax_format: D3.time.format('%b %Y'), + chart_type: c_data.length !== 0 ? 'line' : 'missing-data', + missing_text: 'No data', + show_secondary_x_label: false, + x_extended_ticks: true, + legend: labels, + legend_target: '.comparison_legend', + show_tooltips: false, + aggregate_rollover: true, + show_year_markers: true, + point_size : 3.5, + transition_on_update: true, + interplate: 'linear', + interpolate_tension: 1, + area: false, + y_label: _this.props.translation.y_axis_label, + show_rollover_text: false, + mouseover: function(d, i) { + if (!d.values) { + d.values = [d]; + } + if (c_data.length) { + for (i = 1; i <= c_data.length; i++) { + var l_span = D3.select(legend_target + ' .mg-line' + i + '-legend-color'); + l_span.text(' '); + l_span.text('— ' + labels[i - 1]); + } + } + d.values.forEach(function(val, index) { + var prefix = D3.formatPrefix(val.value); + var l_span = D3.select(legend_target + ' .mg-line' + val.line_id + '-legend-color'); + l_span.text(' '); + l_span.text('— ' + labels[val.line_id - 1] + ' : ' + prefix.scale(val.value).toFixed(0)); + var format = D3.time.format('%b %Y'); + D3.select('#region_comparison_total_trans').text( _this.props.translation.comparison.total_trans[_this.props.activeRegion.region_type] + ' '+ format(val.date) + ': ' + val.total_trans); + }); + }, + mouseout: function(d, i) { + if (!d.values) { + d.values = [d]; + } + D3.select('#region_comparison_total_trans').text(''); + d.values.forEach(function(val, index) { + var l_span = D3.select(legend_target + ' .mg-line' + val.line_id + '-legend-color'); + l_span.text(' '); + l_span.text('— ' + labels[val.line_id - 1]); + }); + } + }); + + }, + stepChange: function(event){ + this.setState({ + active_step : event.target.value + }); + + ga('send', 'event', { + eventCategory: 'Benchmark chart step', + eventAction: 'Selected', + eventLabel:this.props.translation.overview.labels[event.target.value- 1] + }); + + this.loadChart(); + }, + lineChange: function(event){ + + var active_compare_lines = []; + D3.selectAll('.regionSelector').each(function() { + if (this.checked === true) { + active_compare_lines.push(this.value); + } + }); + this.setState({ + active_lines : active_compare_lines + }); + + ga('send', 'event', { + eventCategory: 'Benchmark chart step', + eventAction: 'Toggled' + event.target.checked ? 'ON': 'OFF', + eventLabel: event.target.dataset.region + }); + + this.loadChart(); + }, + componentDidMount: function() { + this.loadChart(); + }, + componentDidUpdate: function(){ + this.loadChart(); + }, + componentWillReceiveProps: function(nextProps){ + + if(!nextProps.activeRegion) { + return; + } + var comparison_lines = nextProps.config.comparison_lines.slice(0); + comparison_lines.push(nextProps.activeRegion.region_type); + this.setState({ + comparison_lines : comparison_lines, + active_lines : comparison_lines + }); + }, + render: function(){ + var _this = this; + return ( +
+
+

{this.props.translation && this.props.translation.comparison.title}

+

+ {this.props.translation && this.props.translation.comparison.description} + +

+ +
+ { + this.state.comparison_lines.map(function(line, i) { + + var region = Region.find(_this.props.config.role, _this.props.activeRegion, _this.props.performance, line); + var label = region[line + '_name'] + ' ' + _this.props.translation.comparison.labels[line]; + var selected = _this.state.active_lines.indexOf(line) !== -1; + return ( +
+ +
+ ); + }) + } +
+
+
+
+
+
{if (el){this.elem = el;}}}>
+
+
+ ); + } +}); + + +export default ComparisonChart; + + + + + + + diff --git a/assets/scripts/components/performance/overview-chart.jsx b/assets/scripts/components/performance/overview-chart.jsx new file mode 100644 index 00000000..11131a07 --- /dev/null +++ b/assets/scripts/components/performance/overview-chart.jsx @@ -0,0 +1,124 @@ +'use strict'; + +import React from 'react'; +import MG from '../../lib/mg'; + +const D3 = require('d3'); +const Parser = require('../../lib/parser'); +const Region = require('../../lib/region'); + + +const OverviewChart = React.createClass({ + + loadChart: function(){ + + var _this = this; + var data = Region.overview_data(_this.props.config.role, _this.props.activeRegion, _this.props.performance); + if(!data){ + return; + } + var legend_target = '.region_legend'; + var parsed_data = Parser.lines({ + data: data, + col: [1, 2, 3, 4, 5, 6, 7], + isCumulative: true + }); + + MG.data_graphic({ + title: '', + target: _this.elem, + left: 100, + width: 600, + height: 500, + full_width: true, + data: parsed_data, + chart_type: parsed_data.length !== 0 ? 'line' : 'missing-data', + missing_text: 'No data', + transition_on_update: true, + aggregate_rollover: true, + show_tooltips: false, + interplate: 'linear', + interpolate_tension: .98, + area: true, + show_secondary_x_label: false, + x_extended_ticks: true, + xax_count: 5, + xax_format: D3.time.format('%b %Y'), + decimals: 0, + baselines: [{ + value: 15, + label: 'Statutory Limit' + }], + point_size : 3.5, + legend: _this.props.translation.overview.labels, + legend_target: '.region_legend', + y_label: _this.props.translation.y_axis_label, + mouseover: function(d, i) { + if (!d.values) { + d.values = [d]; + } + if (parsed_data.length) { + for (i = 1; i <= parsed_data.length; i++) { + var l_span = D3.select(legend_target + ' .mg-line' + i + '-legend-color'); + l_span.text(' '); + l_span.text('— ' + _this.props.translation.overview.labels[i - 1]); + } + } + var format = D3.time.format('%b %Y'); + d.values.forEach(function(val, index) { + var l_span = D3.select(legend_target + ' .mg-line' + val.line_id + '-legend-color'); + l_span.text(' '); + var no_days = d.values[index - 1] ? (val.value - d.values[index - 1].value).toFixed(0) : (val.value).toFixed(0); + l_span.text('— ' + _this.props.translation.overview.labels[val.line_id - 1] + ' : ' + no_days); + D3.select('#region_performance_total_trans').text(format(val.date) + ': ' + val.total_trans); + }); + D3.select('.mg-active-datapoint tspan:first-child').text(format(d.values[0].date)); + }, + mouseout: function(d, i) { + if (!d.values) { + d.values = [d]; + } + D3.select('#region_performance_total_trans').text(''); + d.values.forEach(function(val, index) { + var l_span = D3.select(legend_target + ' .mg-line' + val.line_id + '-legend-color'); + l_span.text(' '); + l_span.text('— ' + _this.props.translation.overview.labels[index]); + }); + } + }); + }, + componentDidMount: function() { + this.loadChart(); + }, + componentDidUpdate: function(){ + this.loadChart(); + }, + render: function(){ + return ( +
+
+

{this.props.translation && this.props.translation.overview.title}

+

+ {this.props.translation && this.props.translation.overview.description} + +

+
+
{this.props.translation && this.props.translation.total_trans}
+
+
+
{if (el){this.elem = el;}}}>
+
+
+ ); + } +}); + + +export default OverviewChart; + + + + + + + diff --git a/assets/scripts/components/performance/subnav.jsx b/assets/scripts/components/performance/subnav.jsx new file mode 100644 index 00000000..dee65eda --- /dev/null +++ b/assets/scripts/components/performance/subnav.jsx @@ -0,0 +1,57 @@ +'use strict'; + +import React from 'react'; +import Select from 'react-select'; + +const Regions = require('../../lib/region'); + +const Subnav = React.createClass({ + + getInitialState: function(){ + return { + value: null + }; + }, + renderOption: function(option) { + return {option.label}; + }, + renderValue: function(option) { + return {option.label}; + }, + setValue: function(value) { + this.setState({ value }); + this.props.onRegionChange(value); + + ga('send', 'event', { + eventCategory: 'Performance region dropdown', + eventAction: 'Selected', + eventLabel: value.value + }); + }, + componentWillReceiveProps : function(nextProps){ + this.setState({ value: nextProps.defaultRegion }); + }, + render: function(){ + var list = Regions.list(this.props.performance, this.props.role); + return ( +
+ {this.state.value && this.state.value.label}   + ' + - internals.data.monthwise[comparison_line][comparison_line + '_name'] + ' ' + internals.data.config.compare_chart_labels[comparison_line] + - '' + - '
'; - }); - return template; -} - -function comparisonLabels(internals) { - var labels = []; - internals.active_compare_lines.forEach(function(comparison_line, index) { - labels.push(internals.data.monthwise[comparison_line][comparison_line + '_name'] + ' ' + internals.data.config.compare_chart_labels[comparison_line]); - }); - return labels; -}; - - - -function drawRegionComparison(val, internals) { - var c_data = []; - - internals.active_compare_lines.forEach(function(comparison_line, index) { - - var line_data = Parser.lines({ - data: internals.data.monthwise[comparison_line].data, - past_n_days: internals.past_n_days, - col: [val], - isCumulative: false - }); - - if (line_data[0]) { - c_data.push(line_data[0]); // Workaround to append region data - } - - }); - Chart.singular({ - data: c_data, - target: '#region_comparison', - legend_target: '.comparison_legend', - labels: comparisonLabels(internals), - area: false, - min_x: Util.overviewLimits(internals).min_x, - y_axis_label : internals.data.config.y_axis_label - }); -} - -function bindEvents(internals) { - // Time period Selection - D3.selectAll('#modify-time-period-controls').on('change', function() { - internals.past_n_days = D3.event.target.value; - drawRegionPerformance(internals); - drawRegionComparison(internals.stepwise_compare_step, internals); - }); - - - //Stepwise charts step selection - D3.selectAll('.regionSelector').on('click', function() { - internals.active_compare_lines = []; - D3.selectAll('.regionSelector').each(function() { - if (this.checked === true) { - internals.active_compare_lines.push(this.value); - } - }); - drawRegionComparison(internals.stepwise_compare_step, internals); - }); - - // Step Selection - D3.selectAll('#modify-step-controls').on('change', function() { - internals.stepwise_compare_step = D3.event.target.value; - drawRegionComparison(internals.stepwise_compare_step, internals); - }); -} diff --git a/assets/scripts/vendor/dynatable.js b/assets/scripts/vendor/dynatable.js deleted file mode 100755 index 02b573ca..00000000 --- a/assets/scripts/vendor/dynatable.js +++ /dev/null @@ -1,1731 +0,0 @@ -/* - * jQuery Dynatable plugin 0.3.1 - * - * Copyright (c) 2014 Steve Schwartz (JangoSteve) - * - * Dual licensed under the AGPL and Proprietary licenses: - * http://www.dynatable.com/license/ - * - * Date: Tue Jan 02 2014 - */ -// - -(function($) { - var defaults, - mergeSettings, - dt, - Model, - modelPrototypes = { - dom: Dom, - domColumns: DomColumns, - records: Records, - recordsCount: RecordsCount, - processingIndicator: ProcessingIndicator, - state: State, - sorts: Sorts, - sortsHeaders: SortsHeaders, - queries: Queries, - inputsSearch: InputsSearch, - paginationPage: PaginationPage, - paginationPerPage: PaginationPerPage, - paginationLinks: PaginationLinks - }, - utility, - build, - processAll, - initModel, - defaultRowWriter, - defaultCellWriter, - defaultAttributeWriter, - defaultAttributeReader; - - //----------------------------------------------------------------- - // Cached plugin global defaults - //----------------------------------------------------------------- - - defaults = { - features: { - paginate: true, - sort: true, - pushState: true, - search: true, - recordCount: true, - perPageSelect: true - }, - table: { - defaultColumnIdStyle: 'camelCase', - columns: null, - headRowSelector: 'thead tr', // or e.g. tr:first-child - bodyRowSelector: 'tbody tr', - headRowClass: null, - copyHeaderAlignment: true, - copyHeaderClass: false - }, - inputs: { - queries: null, - sorts: null, - multisort: ['ctrlKey', 'shiftKey', 'metaKey'], - page: null, - queryEvent: 'blur change', - recordCountTarget: null, - recordCountPlacement: 'after', - paginationLinkTarget: null, - paginationLinkPlacement: 'after', - paginationClass: 'dynatable-pagination-links', - paginationLinkClass: 'dynatable-page-link', - paginationPrevClass: 'dynatable-page-prev', - paginationNextClass: 'dynatable-page-next', - paginationActiveClass: 'dynatable-active-page', - paginationDisabledClass: 'dynatable-disabled-page', - paginationPrev: 'Previous', - paginationNext: 'Next', - paginationGap: [1,2,2,1], - searchTarget: null, - searchPlacement: 'before', - searchText: 'Search: ', - perPageTarget: null, - perPagePlacement: 'before', - perPageText: 'Show: ', - pageText: 'Pages: ', - recordCountPageBoundTemplate: '{pageLowerBound} to {pageUpperBound} of', - recordCountPageUnboundedTemplate: '{recordsShown} of', - recordCountTotalTemplate: '{recordsQueryCount} {collectionName}', - recordCountFilteredTemplate: ' (filtered from {recordsTotal} total records)', - recordCountText: 'Showing', - recordCountTextTemplate: '{text} {pageTemplate} {totalTemplate} {filteredTemplate}', - recordCountTemplate: '{textTemplate}', - processingText: 'Processing...' - }, - dataset: { - ajax: false, - ajaxUrl: null, - ajaxCache: null, - ajaxOnLoad: false, - ajaxMethod: 'GET', - ajaxDataType: 'json', - totalRecordCount: null, - queries: {}, - queryRecordCount: null, - page: null, - perPageDefault: 10, - perPageOptions: [10,20,50,100], - sorts: {}, - sortsKeys: [], - sortTypes: {}, - records: null - }, - writers: { - _rowWriter: defaultRowWriter, - _cellWriter: defaultCellWriter, - _attributeWriter: defaultAttributeWriter - }, - readers: { - _rowReader: null, - _attributeReader: defaultAttributeReader - }, - params: { - dynatable: 'dynatable', - queries: 'queries', - sorts: 'sorts', - page: 'page', - perPage: 'perPage', - offset: 'offset', - records: 'records', - record: null, - queryRecordCount: 'queryRecordCount', - totalRecordCount: 'totalRecordCount' - } - }; - - //----------------------------------------------------------------- - // Each dynatable instance inherits from this, - // set properties specific to instance - //----------------------------------------------------------------- - - dt = { - init: function(element, options) { - this.settings = mergeSettings(options); - this.element = element; - this.$element = $(element); - - // All the setup that doesn't require element or options - build.call(this); - - return this; - }, - - process: function(skipPushState) { - processAll.call(this, skipPushState); - } - }; - - //----------------------------------------------------------------- - // Cached plugin global functions - //----------------------------------------------------------------- - - mergeSettings = function(options) { - var newOptions = $.extend(true, {}, defaults, options); - - // TODO: figure out a better way to do this. - // Doing `extend(true)` causes any elements that are arrays - // to merge the default and options arrays instead of overriding the defaults. - if (options) { - if (options.inputs) { - if (options.inputs.multisort) { - newOptions.inputs.multisort = options.inputs.multisort; - } - if (options.inputs.paginationGap) { - newOptions.inputs.paginationGap = options.inputs.paginationGap; - } - } - if (options.dataset && options.dataset.perPageOptions) { - newOptions.dataset.perPageOptions = options.dataset.perPageOptions; - } - } - - return newOptions; - }; - - build = function() { - this.$element.trigger('dynatable:preinit', this); - - for (model in modelPrototypes) { - if (modelPrototypes.hasOwnProperty(model)) { - var modelInstance = this[model] = new modelPrototypes[model](this, this.settings); - if (modelInstance.initOnLoad()) { - modelInstance.init(); - } - } - } - - this.$element.trigger('dynatable:init', this); - - if (!this.settings.dataset.ajax || (this.settings.dataset.ajax && this.settings.dataset.ajaxOnLoad) || this.settings.features.paginate || (this.settings.features.sort && !$.isEmptyObject(this.settings.dataset.sorts))) { - this.process(); - } - }; - - processAll = function(skipPushState) { - var data = {}; - - this.$element.trigger('dynatable:beforeProcess', data); - - if (!$.isEmptyObject(this.settings.dataset.queries)) { data[this.settings.params.queries] = this.settings.dataset.queries; } - // TODO: Wrap this in a try/rescue block to hide the processing indicator and indicate something went wrong if error - this.processingIndicator.show(); - - if (this.settings.features.sort && !$.isEmptyObject(this.settings.dataset.sorts)) { data[this.settings.params.sorts] = this.settings.dataset.sorts; } - if (this.settings.features.paginate && this.settings.dataset.page) { - var page = this.settings.dataset.page, - perPage = this.settings.dataset.perPage; - data[this.settings.params.page] = page; - data[this.settings.params.perPage] = perPage; - data[this.settings.params.offset] = (page - 1) * perPage; - } - if (this.settings.dataset.ajaxData) { $.extend(data, this.settings.dataset.ajaxData); } - - // If ajax, sends query to ajaxUrl with queries and sorts serialized and appended in ajax data - // otherwise, executes queries and sorts on in-page data - if (this.settings.dataset.ajax) { - var _this = this; - var options = { - type: _this.settings.dataset.ajaxMethod, - dataType: _this.settings.dataset.ajaxDataType, - data: data, - error: function(xhr, error) { - }, - success: function(response) { - _this.$element.trigger('dynatable:ajax:success', response); - // Merge ajax results and meta-data into dynatables cached data - _this.records.updateFromJson(response); - // update table with new records - _this.dom.update(); - - if (!skipPushState && _this.state.initOnLoad()) { - _this.state.push(data); - } - }, - complete: function() { - _this.processingIndicator.hide(); - } - }; - // Do not pass url to `ajax` options if blank - if (this.settings.dataset.ajaxUrl) { - options.url = this.settings.dataset.ajaxUrl; - - // If ajaxUrl is blank, then we're using the current page URL, - // we need to strip out any query, sort, or page data controlled by dynatable - // that may have been in URL when page loaded, so that it doesn't conflict with - // what's passed in with the data ajax parameter - } else { - options.url = utility.refreshQueryString(window.location.href, {}, this.settings); - } - if (this.settings.dataset.ajaxCache !== null) { options.cache = this.settings.dataset.ajaxCache; } - - $.ajax(options); - } else { - this.records.resetOriginal(); - this.queries.run(); - if (this.settings.features.sort) { - this.records.sort(); - } - if (this.settings.features.paginate) { - this.records.paginate(); - } - this.dom.update(); - this.processingIndicator.hide(); - - if (!skipPushState && this.state.initOnLoad()) { - this.state.push(data); - } - } - this.$element.trigger('dynatable:afterProcess', data); - }; - - function defaultRowWriter(rowIndex, record, columns, cellWriter) { - var tr = ''; - - // grab the record's attribute for each column - for (var i = 0, len = columns.length; i < len; i++) { - tr += cellWriter(columns[i], record); - } - - return '' + tr + ''; - }; - - function defaultCellWriter(column, record) { - var html = column.attributeWriter(record), - td = '