diff --git a/src/web_console/README.md b/src/web_console/README.md index c4c52ed..6e5e6c3 100644 --- a/src/web_console/README.md +++ b/src/web_console/README.md @@ -18,4 +18,4 @@ npm run dev ``` -Open [http://localhost:6001](http://localhost:6001) \ No newline at end of file +Open [http://localhost:8300](http://localhost:8300) \ No newline at end of file diff --git a/src/web_console/configuration/system_configs.js b/src/web_console/configuration/system_configs.js index 25d3b8c..2c9a24d 100644 --- a/src/web_console/configuration/system_configs.js +++ b/src/web_console/configuration/system_configs.js @@ -12,49 +12,17 @@ var enums = new Enums(); //noinspection JSUnresolvedVariable exports.setupEnvironment = function () { - var env = process.env.NODE_ENV || 'development'; - ENV = env; - if (undefined == typeof env || null == env || "" == env || enums.APP_PRODUCTION_MODE == env) { - MYSQL_DB_SERVER_ADDRESS = "root"; - MYSQL_DB_NAME = "irext"; - MYSQL_DB_USER = "root"; - MYSQL_DB_PASSWORD = "root"; - FILE_TEMP_PATH = "~/home/strawmanbobi/rc_extension"; - PYTHON_PATH = "/usr/bin/python"; - LISTEN_PORT = "80"; - SERVER_ADDRESS = "localhost"; - REDIS_HOST = "localhost"; - REDIS_PORT = "6379"; - REDIS_PASSWORD = ""; - EXTERNAL_SERVER_ADDRESS = "irext.net"; - EXTERNAL_SERVER_PORT = "80" - } else if (enums.APP_DEVELOPMENT_MODE == env) { - MYSQL_DB_SERVER_ADDRESS = "localhost"; - MYSQL_DB_NAME = "irext"; - MYSQL_DB_USER = "root"; - MYSQL_DB_PASSWORD = "root"; - FILE_TEMP_PATH = "D:/rc_extension"; - PYTHON_PATH = "C:/Python27/python.exe"; - LISTEN_PORT = "6001"; - SERVER_ADDRESS = "localhost"; - REDIS_HOST = "localhost"; - REDIS_PORT = "6379"; - REDIS_PASSWORD = ""; - EXTERNAL_SERVER_ADDRESS = "192.168.137.128"; - EXTERNAL_SERVER_PORT = "8300" - } else if (enums.APP_USERDEBUG_MODE == env) { - MYSQL_DB_SERVER_ADDRESS = "localhost"; - MYSQL_DB_NAME = "irext"; - MYSQL_DB_USER = "root"; - MYSQL_DB_PASSWORD = "root"; - FILE_TEMP_PATH = "D:/rc_extension"; - PYTHON_PATH = "/usr/bin/python"; - LISTEN_PORT = "80"; - SERVER_ADDRESS = "localhost"; - REDIS_HOST = "localhost"; - REDIS_PORT = "6379"; - REDIS_PASSWORD = ""; - EXTERNAL_SERVER_ADDRESS = "www.strawmanbobi.com"; - EXTERNAL_SERVER_PORT = "8300" - } + MYSQL_DB_SERVER_ADDRESS = "localhost"; + MYSQL_DB_NAME = "irext"; + MYSQL_DB_USER = "root"; + MYSQL_DB_PASSWORD = "root"; + FILE_TEMP_PATH = "~/home/your_name/rc_extension"; + PYTHON_PATH = "/usr/bin/python"; + LISTEN_PORT = "80"; + SERVER_ADDRESS = "localhost"; + REDIS_HOST = "localhost"; + REDIS_PORT = "6379"; + REDIS_PASSWORD = ""; + EXTERNAL_SERVER_ADDRESS = "irext.net"; + EXTERNAL_SERVER_PORT = "80" }; \ No newline at end of file diff --git a/src/web_console/model/category_dao.js b/src/web_console/model/category_dao.js index c8ab785..b6ffb54 100644 --- a/src/web_console/model/category_dao.js +++ b/src/web_console/model/category_dao.js @@ -87,7 +87,6 @@ Category.listCategories = function(conditions, from, count, sortField, callback) } }); } - }; Category.getCategoryByID = function(categoryID, callback) { diff --git a/src/web_console/routes/index.js b/src/web_console/routes/index.js index 72ce8b3..7acb262 100644 --- a/src/web_console/routes/index.js +++ b/src/web_console/routes/index.js @@ -8,4 +8,3 @@ var server = require('../irext_console.js'); require('./navigation_routes.js'); require('./code_manage_routes.js'); require('./certificate_routes.js'); -require('./stat_routes.js'); diff --git a/src/web_console/routes/stat_routes.js b/src/web_console/routes/stat_routes.js deleted file mode 100644 index c1f395d..0000000 --- a/src/web_console/routes/stat_routes.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Created by Strawmanbobi - * 2016-11-27 - */ -var app = require('../irext_console.js'); -var statService = require('../services/stat_service.js'); - -app.get('/irext/stat/generic_count', statService.genericCount); -app.get('/irext/stat/stat_categories', statService.statCategories); -app.get('/irext/stat/stat_brands', statService.statBrands); -app.get('/irext/stat/stat_cities', statService.statCities); \ No newline at end of file diff --git a/src/web_console/services/stat_service.js b/src/web_console/services/stat_service.js deleted file mode 100644 index 172cdce..0000000 --- a/src/web_console/services/stat_service.js +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Created by Strawmanbobi - * 2016-11-27 - */ - -// system inclusion -var constants = require('../mini_poem/configuration/constants'); -var logger = require('../mini_poem/logging/logger4js').helper; - -var formidable = require('formidable'); -var fs = require('fs'); - -// local inclusion -var ServiceResponse = require('../response/service_response.js'); -var StatResponse = require('../response/stat_response.js'); -var IntegerResponse = require('../response/integer_response'); - - -var statLogic = require('../work_unit/stat_logic.js'); - -var Enums = require('../constants/enums'); -var ErrorCode = require('../constants/error_code'); - -var enums = new Enums(); -var errorCode = new ErrorCode(); - -/* - * function : Count remote of irext remote and device - * parameter : stat_type - * return : Customized statistics response - */ -exports.genericCount = function(req, res) { - var statType = req.query.stat_type; - - var statResponse = new StatResponse(); - statLogic.countRemoteWorkUnit(statType, function(countRemoteErr, statContent) { - statResponse.status = countRemoteErr; - statResponse.entity = statContent; - res.send(statResponse); - res.end(); - }); -}; - -/* - * function : Stat categories - * parameter : - * return : Customized statistics response - */ -exports.statCategories = function(req, res) { - var statResponse = new StatResponse(); - statLogic.statCategoriesWorkUnit(function(statCategoriesErr, statCategories) { - statResponse.status = statCategoriesErr; - statResponse.entity = statCategories; - res.send(statResponse); - res.end(); - }); -}; - -/* - * function : Stat brands - * parameter : - * return : Customized statistics response - */ -exports.statBrands = function(req, res) { - var categoryID = req.query.category_id; - - var statResponse = new StatResponse(); - statLogic.statBrandsWorkUnit(categoryID, function(statBrandsErr, statBrands) { - statResponse.status = statBrandsErr; - statResponse.entity = statBrands; - res.send(statResponse); - res.end(); - }); -}; - -/* - * function : Stat cities - * parameter : - * return : Customized statistics response - */ -exports.statCities = function(req, res) { - var statResponse = new StatResponse(); - statLogic.statCitiesWorkUnit(function(statCitiesErr, statCities) { - statResponse.status = statCitiesErr; - statResponse.entity = statCities; - res.send(statResponse); - res.end(); - }); -}; \ No newline at end of file diff --git a/src/web_console/web/public_js/script_bower.sh b/src/web_console/web/public_js/script_bower.sh index edf4e59..84ed3aa 100755 --- a/src/web_console/web/public_js/script_bower.sh +++ b/src/web_console/web/public_js/script_bower.sh @@ -20,4 +20,7 @@ bower install select2 --allow-root echo "bower install bootstrap-spinner" bower install bootstrap-spinner --allow-root +echo "bower install highcharts" +bower install highcharts + echo "bower install done" diff --git a/src/web_console/web/stat/css/stat.css b/src/web_console/web/stat/css/stat.css deleted file mode 100644 index fa2fe73..0000000 --- a/src/web_console/web/stat/css/stat.css +++ /dev/null @@ -1,91 +0,0 @@ -/* - * create by strawmanbobi - * 2016-11-30 - */ - -/* Space out content a bit */ - -body { - padding-bottom: 20px; - font-family: 微软雅黑, Arial; -} - -.starter-template { - padding: 40px 15px; -} - -/* Everything but the jumbotron gets side spacing for mobile first views */ -.header, -.marketing, -.footer { - padding-left: 15px; - padding-right: 15px; -} - -/* Custom page header */ -.header { - border-bottom: 1px solid #e5e5e5; -} -/* Make the masthead heading the same height as the navigation */ -.header h3 { - margin-top: 0; - margin-bottom: 0; - line-height: 40px; - padding-bottom: 19px; -} - -/* Custom page footer */ -.footer { - padding-top: 19px; - color: #777; - border-top: 1px solid #e5e5e5; -} - -/* Customize container */ -@media (min-width: 768px) { -} -.container-narrow > hr { - margin: 30px 0; -} - -/* Main marketing message and sign up button */ -.jumbotron { - text-align: center; - border-bottom: 1px solid #e5e5e5; -} -.jumbotron .btn { - font-size: 21px; - padding: 14px 24px; -} - -/* Supporting marketing content */ -.marketing { - margin: 40px 0; -} -.marketing p + h4 { - margin-top: 28px; -} - -.pointer { - cursor: pointer -} - -/* Responsive: Portrait tablets and up */ -@media screen and (min-width: 768px) { - /* Remove the padding we set earlier */ - .header, - .marketing, - .footer { - padding-left: 0; - padding-right: 0; - } - /* Space out the masthead */ - .header { - margin-bottom: 30px; - } - /* Remove the bottom border on the jumbotron for visual effect */ - .jumbotron { - border-bottom: 0; - } -} - diff --git a/src/web_console/web/stat/index.html b/src/web_console/web/stat/index.html deleted file mode 100644 index 4d79f8a..0000000 --- a/src/web_console/web/stat/index.html +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - irext 控制台 - - - - - - - - - - - - - - -
- -
- - - -
-
-
-
-
-

全世界共有 台 irext 成功激活

-

-

底座激活数:

-
-
-
-
-

台家用电器已被 irext 成功控制

-
-
-
-
-
-
-
- -
-
-
- -
-
-
- - - - - - - - - \ No newline at end of file diff --git a/src/web_console/web/stat/js/stat.js b/src/web_console/web/stat/js/stat.js deleted file mode 100644 index 13d20bc..0000000 --- a/src/web_console/web/stat/js/stat.js +++ /dev/null @@ -1,341 +0,0 @@ -/** - * Created by Strawmanbobi - * 2016-01-04 - */ - -var LS_KEY_ID = "user_name"; -var LS_KEY_TOKEN = "token"; -var id, token; - -var categoriesStated = false; - -var colorClass = ["default", "primary", "success", "warning", "danger", "info"]; - -// global container var -var gCategories = []; -// 2-dimensions brand array -var gBrands = []; -// 1-dimension city array -var gCities = []; - -$("#menu_toggle").click(function(e) { - e.preventDefault(); - $("#wrapper").toggleClass("toggled"); -}); - -$(document).ready(function() { - id = localStorage.getItem(LS_KEY_ID); - token = localStorage.getItem(LS_KEY_TOKEN); - showMenu(id, token, "stat"); - - $("#main_tab a:first").tab("show"); - - getRemoteInstanceCount(); - getDeviceCount(); - getRemoteCount(); -}); - -///////////////////////////// Event functions ///////////////////////////// -function onStatCategories() { - if (true == categoriesStated) { - return; - } - console.debug("stat categories"); - statCategories(); -} - -function onStatBrands(categoryIndex) { - var categoryID = 0; - if (true == gBrands[categoryIndex].brandStated) { - return; - } - categoryID = gCategories[categoryIndex].id; - - if (3 != categoryID) { - statBrands(gCategories[categoryIndex].id, categoryIndex); - } else { - statCities(gCategories[categoryIndex].id, categoryIndex); - } - -} - -///////////////////////////// Data functions ///////////////////////////// -function getRemoteInstanceCount() { - $.ajax({ - url: "/irext/stat/generic_count?stat_type=0&id="+id+"&token="+token, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - refreshActiveRemoteInstance(response.entity); - } else { - console.log("get remote instance count failed"); - } - }, - error: function () { - console.log("get remote instance count failed"); - } - }); -} - -function getDeviceCount() { - $.ajax({ - url: "/irext/stat/generic_count?stat_type=1&id="+id+"&token="+token, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - refreshActiveDeviceInstance(response.entity); - } else { - console.log("get device count failed"); - } - }, - error: function () { - console.log("get device count failed"); - } - }); -} - -function getRemoteCount() { - $.ajax({ - url: "/irext/stat/generic_count?stat_type=2&id="+id+"&token="+token, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - refreshActiveRemote(response.entity); - } else { - console.log("get remote count failed"); - } - }, - error: function () { - console.log("get remote count failed"); - } - }); -} - -function statCategories() { - $.ajax({ - url: "/irext/stat/stat_categories?id="+id+"&token="+token, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - gCategories = response.entity; - refreshCategoryList(); - } else { - console.log("stat categories failed"); - } - }, - error: function () { - console.log("stat categories failed"); - } - }); -} - -function statBrands(categoryID, categoryIndex) { - $.ajax({ - url: "/irext/stat/stat_brands?id="+id+"&token="+token+"&category_id="+categoryID, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - gBrands[categoryIndex].brands = response.entity; - // console.log("brands stat result = " + JSON.stringify(gBrands[categoryIndex].brands)); - refreshBrandList(categoryID, categoryIndex); - } else { - console.log("stat brands failed"); - } - }, - error: function () { - console.log("stat brands failed"); - } - }); -} - -function statCities(categoryID, categoryIndex) { - $.ajax({ - url: "/irext/stat/stat_cities?id="+id+"&token="+token, - type: "GET", - timeout: 20000, - success: function (response) { - if(response.status.code == 0) { - gCities.cities = response.entity; - console.log("cities stat result = " + JSON.stringify(gCities.cities)); - refreshCityList(categoryID, categoryIndex); - } else { - console.log("stat cities failed"); - } - }, - error: function () { - console.log("stat cities failed"); - } - }); -} - -///////////////////////////// UI functions ///////////////////////////// -function refreshActiveRemoteInstance(count) { - var remoteInstancePanel = $("#ucon_count"); - remoteInstancePanel.empty(); - remoteInstancePanel.append(count); -} - -function refreshActiveDeviceInstance(count) { - var deviceInstancePanel = $("#device_count"); - deviceInstancePanel.empty(); - deviceInstancePanel.append(count); -} - -function refreshActiveRemote(count) { - var remoteCountPanel = $("#remote_count"); - remoteCountPanel.empty(); - remoteCountPanel.append(count); -} - -function refreshCategoryList() { - var categoryContent = ""; - gBrands = new Array(); - for (var i = 0; i < gCategories.length; i++) { - var category = gCategories[i]; - - if (category.id == 11) { - category.name = "機上盒"; - } - var panelID = "category_" + category.id; - var collapseID = "collapse" + category.id; - var colorSpace = i % 6; - var includingText = ""; - if (3 != category.id) { - includingText = "个品牌"; - } else { - includingText = "个省份"; - } - // console.log(colorClass[colorSpace]); - categoryContent += - "
" + - "" + - "
" + - "
" + - "正在加载..." + - "
" + - "
" + - "
"; - gBrands[i] = new Array(); - gBrands[i].brandStated = false; - } - $("#categories_panel").html(categoryContent); - categoriesStated = true; -} - -function refreshBrandList(categoryID, categoryIndex) { - // draw charts with highcharts - // adjust the container of charts according to the number of brands in this category - var containerHeight = gBrands[categoryIndex].brands.length * 30 + 200; - console.log("container height = " + containerHeight); - $("#brand_charts_" + categoryID).css("width", "100%"); - $("#brand_charts_" + categoryID).css("height", containerHeight + "px"); - $("#brand_charts_" + categoryID).css("padding", "0px"); - - // generate brand names and supported remote index counts - var brandNames = []; - var remoteIndexCounts = []; - for (var i = 0; i < gBrands[categoryIndex].brands.length; i++) { - brandNames[i] = gBrands[categoryIndex].brands[i].name; - remoteIndexCounts[i] = gBrands[categoryIndex].brands[i].remote_indexes_count; - } - - $("#brand_charts_" + categoryID).highcharts({ - chart: { - type: "bar", - style: { - fontFamily: '微软雅黑' - }, - events: { - load: function(event) { - // nothing to do - } - } - }, - title: { - text: gCategories[categoryIndex].name + "品牌分布" - }, - xAxis: { - categories: brandNames - }, - yAxis: { - title: { - text: '支持型号数' - } - }, - series: [{ - name: '型号数', - data: remoteIndexCounts, - dataLabels: { - enabled: true - } - }] - }); - - gBrands[categoryIndex].brandStated = true; -} - -function refreshCityList(categoryID, categoryIndex) { - // draw charts with highcharts - // adjust the container of charts according to the number of brands in this category - var containerHeight = gCities.cities.length * 30 + 200; - console.log("container height = " + containerHeight); - $("#brand_charts_" + categoryID).css("width", "100%"); - $("#brand_charts_" + categoryID).css("height", containerHeight + "px"); - $("#brand_charts_" + categoryID).css("padding", "0px"); - - // generate brand names and supported remote index counts - var provinceNames = []; - var cityCounts = []; - for (var i = 0; i < gCities.cities.length; i++) { - provinceNames[i] = gCities.cities[i].name; - cityCounts[i] = gCities.cities[i].city_count; - } - - $("#brand_charts_" + categoryID).highcharts({ - chart: { - type: "bar", - style: { - fontFamily: '微软雅黑' - }, - events: { - load: function(event) { - // nothing to do - } - } - }, - title: { - text: gCategories[categoryIndex].name + "地区分布" - }, - xAxis: { - categories: provinceNames - }, - yAxis: { - title: { - text: '支持城市数' - } - }, - series: [{ - name: '城市数', - data: cityCounts, - dataLabels: { - enabled: true - } - }] - }); - - gBrands[categoryIndex].brandStated = true; -} \ No newline at end of file diff --git a/src/web_console/work_unit/stat_logic.js b/src/web_console/work_unit/stat_logic.js deleted file mode 100644 index 135e8f5..0000000 --- a/src/web_console/work_unit/stat_logic.js +++ /dev/null @@ -1,133 +0,0 @@ -/** - * Created by strawmanbobi - * 2016-11-27 - */ - -// global inclusion -require('../mini_poem/configuration/constants'); -var RequestSender = require('../mini_poem/http/request.js'); -var Map = require('../mini_poem/mem/map.js'); -var logger = require('../mini_poem/logging/logger4js').helper; - -// local inclusion - -var Enums = require('../constants/enums.js'); -var ErrorCode = require('../constants/error_code.js'); - -var enums = new Enums(); -var errorCode = new ErrorCode(); - -var REQUEST_APP_KEY = "d6119900556c4c1e629fd92d"; -var REQUEST_APP_TOKEN = "fcac5496cba7a12b3bae34abf061f526"; - -// out going HTTP request parameters -var PRIMARY_SERVER_ADDRESS = "irext.net"; -// var PRIMARY_SERVER_ADDRESS = "127.0.0.1"; -var PRIMARY_SERVER_PORT = "8200"; - -var STAT_GENERIC_COUNT_SERVICE = "/irext/stat/generic_count"; -var STAT_CATEGORIES_SERVICE = "/irext/stat/stat_categories"; -var STAT_BRANDS_SERVICE = "/irext/stat/stat_brands"; -var STAT_CITIES_SERVICE = "/irext/stat/stat_cities"; - -exports.countRemoteWorkUnit = function(statType, callback) { - if (parseInt(statType) < parseInt(enums.STAT_TYPE_REMOTE_INSTANCE_ACTIVE) || - parseInt(statType) > parseInt(enums.STAT_TYPE_REMOTE_ACTIVE)) { - logger.warn("stat type might be invalid : " + statType); - callback(errorCode.FAILED, null); - } else { - var options = { - https: false - }; - var queryParams = new Map(); - var countResult = 0; - queryParams.put("app_key", REQUEST_APP_KEY); - queryParams.put("app_token", REQUEST_APP_TOKEN); - queryParams.put("stat_type", statType); - var requestSender = - new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, STAT_GENERIC_COUNT_SERVICE, queryParams); - requestSender.sendGetRequest(options, function(sendRequestErr, response) { - if (sendRequestErr != errorCode.SUCCESS.code) { - logger.error("send request error"); - callback(errorCode.FAILED, null); - } else { - logger.info("send request successfully, response = " + JSON.parse(response).entity); - countResult = JSON.parse(response).entity; - callback(errorCode.SUCCESS, countResult); - } - }); - } -}; - -exports.statCategoriesWorkUnit = function(callback) { - var queryParams = new Map(); - queryParams.put("app_key", REQUEST_APP_KEY); - queryParams.put("app_token", REQUEST_APP_TOKEN); - var options = { - https: false - }; - - var messagesResult = null; - - var requestSender = - new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, STAT_CATEGORIES_SERVICE, queryParams); - - requestSender.sendGetRequest(options, function(sendRequestErr, response) { - if (sendRequestErr != errorCode.SUCCESS.code) { - logger.error("send request error"); - callback(errorCode.FAILED, null); - } else { - messagesResult = JSON.parse(response).entity; - callback(errorCode.SUCCESS, messagesResult); - } - }); -}; - -exports.statBrandsWorkUnit = function(categoryID, callback) { - var queryParams = new Map(); - queryParams.put("app_key", REQUEST_APP_KEY); - queryParams.put("app_token", REQUEST_APP_TOKEN); - queryParams.put("category_id", categoryID); - var options = { - https: false - }; - - var messagesResult = null; - - var requestSender = - new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, STAT_BRANDS_SERVICE, queryParams); - - requestSender.sendGetRequest(options, function(sendRequestErr, response) { - if (sendRequestErr != errorCode.SUCCESS.code) { - logger.error("send request error"); - callback(errorCode.FAILED, null); - } else { - messagesResult = JSON.parse(response).entity; - callback(errorCode.SUCCESS, messagesResult); - } - }); -}; - -exports.statCitiesWorkUnit = function(callback) { - var queryParams = new Map(); - queryParams.put("app_key", REQUEST_APP_KEY); - queryParams.put("app_token", REQUEST_APP_TOKEN); - var options = { - https: false - }; - - var messagesResult = null; - - var requestSender = - new RequestSender(PRIMARY_SERVER_ADDRESS, PRIMARY_SERVER_PORT, STAT_CITIES_SERVICE, queryParams); - - requestSender.sendGetRequest(options, function(sendRequestErr, response) { - if (sendRequestErr != errorCode.SUCCESS.code) { - logger.error("send request error"); - callback(errorCode.FAILED, null); - } else { - messagesResult = JSON.parse(response).entity; - callback(errorCode.SUCCESS, messagesResult); - } - }); -}; \ No newline at end of file