PageRenderTime 30ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Admin/Manager.WebApp/obj/Release/Package/PackageTmp/Scripts/Home/dashboard.js

https://gitlab.com/thanhhung95/managecourse
JavaScript | 381 lines | 268 code | 36 blank | 77 comment | 10 complexity | 1c46de2fc273e1c0bb2996d8f94eafe0 MD5 | raw file
  1. var DashboardGlobal = {
  2. getStatisticsAppWeek: function () {
  3. GetAndDrawAppWeekChartData();
  4. },
  5. getStatisticsWeek: function () {
  6. GetAndDrawWeekChartData();
  7. },
  8. getTodayTasks: function () {
  9. GetTodayTasks();
  10. },
  11. getNotifications: function () {
  12. GetNotifications();
  13. },
  14. notifPage: 1,
  15. notifPagingEnded: false
  16. };
  17. $(function () {
  18. $('#WidgetNotif').on('scroll', function () {
  19. if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
  20. DashboardGlobal.getNotifications();
  21. }
  22. });
  23. setTimeout(function () {
  24. DashboardGlobal.getStatisticsWeek();
  25. }, 500);
  26. setTimeout(function () {
  27. DashboardGlobal.getStatisticsAppWeek();
  28. }, 1000);
  29. setTimeout(function () {
  30. DashboardGlobal.getTodayTasks();
  31. }, 1500);
  32. setTimeout(function () {
  33. DashboardGlobal.getNotifications();
  34. }, 1500);
  35. });
  36. function GetAndDrawWeekChartData() {
  37. var params = $.extend({}, doAjax_params_default);
  38. params['url'] = 'Home/DashBoardStatisticsByWeek';
  39. params['requestType'] = 'POST';
  40. params['showloading'] = false;
  41. params['data'] = {};
  42. params['dataType'] = "json";
  43. params['successCallbackFunction'] = function (result) {
  44. if (result) {
  45. //Chart by week
  46. DrawWeekLineChart(result);
  47. }
  48. };
  49. doAjax(params);
  50. }
  51. function GetAndDrawAppWeekChartData() {
  52. var params = $.extend({}, doAjax_params_default);
  53. params['url'] = 'Home/DashBoardStatisticsAppByWeek';
  54. params['requestType'] = 'POST';
  55. params['showloading'] = false;
  56. params['data'] = {};
  57. params['dataType'] = "json";
  58. params['successCallbackFunction'] = function (result) {
  59. if (result) {
  60. //Chart by week
  61. DrawAppWeekLineChart(result);
  62. }
  63. };
  64. doAjax(params);
  65. }
  66. function GetTodayTasks() {
  67. var params = $.extend({}, doAjax_params_default);
  68. params['url'] = 'Schedule/GetTodayTasks';
  69. params['requestType'] = 'POST';
  70. params['showloading'] = false;
  71. params['data'] = {};
  72. params['dataType'] = "json";
  73. params['successCallbackFunction'] = function (result) {
  74. if (result) {
  75. $("#WidgetTodayTasks").html(result.html).fadeIn();
  76. $("#WidgetTodayTasks").fadeIn();
  77. }
  78. };
  79. doAjax(params);
  80. }
  81. //function GetNotifications() {
  82. // var page = parseInt($("#WidgetNotif").data("page"));
  83. // var isEnded = $("#WidgetNotif").data("ended");
  84. // if (isNaN(page)) {
  85. // page = 0;
  86. // }
  87. // page = page + 1;
  88. // $("#WidgetNotif").attr("data-page", page);
  89. // if (isEnded) {
  90. // return false;
  91. // }
  92. // showItemLoading("#WidgetNotif");
  93. // var params = $.extend({}, doAjax_params_default);
  94. // params['url'] = 'AuthedGlobal/GetDashboardNotification';
  95. // params['requestType'] = 'POST';
  96. // params['showloading'] = false;
  97. // params['data'] = { page: page};
  98. // params['dataType'] = "json";
  99. // params['successCallbackFunction'] = function (result) {
  100. // if (result) {
  101. // if (!result.success) {
  102. // $("#WidgetNotif").attr("data-ended", true);
  103. // if (page === 0 || page === 1 || isNaN(page)) {
  104. // $("#WidgetNotif").append(result.html);
  105. // }
  106. // }
  107. // else {
  108. // $("#WidgetNotif").append(result.html);
  109. // }
  110. // }
  111. // if (page === 0 || page === 1 || isNaN(page)) {
  112. // $("#WidgetNotif").fadeIn();
  113. // }
  114. // hideItemLoading("#WidgetNotif");
  115. // };
  116. // doAjax(params);
  117. //}
  118. function GetNotifications() {
  119. var isEnded = DashboardGlobal.notifPagingEnded;
  120. if (isEnded) {
  121. return false;
  122. }
  123. showItemLoading("#WidgetNotif");
  124. var params = $.extend({}, doAjax_params_default);
  125. params['url'] = 'AuthedGlobal/GetDashboardNotification';
  126. params['requestType'] = 'POST';
  127. params['showloading'] = false;
  128. params['data'] = { page: DashboardGlobal.notifPage };
  129. params['dataType'] = "json";
  130. params['successCallbackFunction'] = function (result) {
  131. if (result) {
  132. if (!result.success) {
  133. DashboardGlobal.notifPagingEnded = true;
  134. if (DashboardGlobal.notifPage === 0 || DashboardGlobal.notifPage === 1) {
  135. $("#WidgetNotif").append(result.html);
  136. }
  137. }
  138. else {
  139. $("#WidgetNotif").append(result.html);
  140. }
  141. }
  142. //if (page === 0 || page === 1 || isNaN(page)) {
  143. // $("#WidgetNotif").fadeIn();
  144. //}
  145. DashboardGlobal.notifPage++;
  146. hideItemLoading("#WidgetNotif");
  147. };
  148. doAjax(params);
  149. }
  150. function DrawWeekLineChart(rootData) {
  151. var DAYS = [
  152. LanguageDic['LB_DATE_MONDAY'],
  153. LanguageDic['LB_DATE_TUESDAY'],
  154. LanguageDic['LB_DATE_WEDNESDAY'],
  155. LanguageDic['LB_DATE_THUSDAY'],
  156. LanguageDic['LB_DATE_FRIDAY'],
  157. LanguageDic['LB_DATE_SATURDAY'],
  158. LanguageDic['LB_DATE_SUNDAY']
  159. ];
  160. //var progress = document.getElementById('animationProgress');
  161. var color = Chart.helpers.color;
  162. Chart.defaults.global.animation.duration = 3000;
  163. //var note = LanguageDic['LB_UPDATE'] + ': UPDATED_AT, ' + LanguageDic['LB_UPDATE_NEXT_TIME'] + ': UPDATE_NEXT';
  164. //note = note.replace('UPDATED_AT', rootData.UpdatedTime).replace('UPDATE_NEXT', rootData.NextUpdate);
  165. var note = LanguageDic['LB_DATA_DAILY_UPDATE_AUTO'];
  166. var dateRangeStr = rootData.FromDateStr + " - " + rootData.ToDateStr;
  167. var lineChartData = {
  168. labels: DAYS,
  169. datasets: [
  170. {
  171. label: LanguageDic['LB_JOB_STATUS_PUBLIC'] + ' (' + rootData.InWeekData.successTotal +')',
  172. backgroundColor: 'rgba(0, 0, 0, 0)',
  173. borderColor: window.chartColors.blue,
  174. borderWidth: 2,
  175. data: rootData.InWeekData.successData
  176. },
  177. {
  178. label: LanguageDic['LB_JOB_STATUS_DRAFT'] + ' (' + rootData.InWeekData.processingTotal + ')',
  179. backgroundColor: 'rgba(0, 0, 0, 0)',
  180. borderColor: window.chartColors.orange,
  181. borderWidth: 2,
  182. data: rootData.InWeekData.processingData
  183. },
  184. {
  185. label: LanguageDic['LB_JOB_STATUS_PENDING'] + ' (' + rootData.InWeekData.failedTotal + ')',
  186. backgroundColor: 'rgba(0, 0, 0, 0)',
  187. borderColor: window.chartColors.red,
  188. borderWidth: 2,
  189. data: rootData.InWeekData.failedData
  190. //hidden: true,
  191. }
  192. ]
  193. };
  194. var ctx = document.getElementById("WeekStatisticsChartCanvas").getContext("2d");
  195. $("#WeekStatisticsChart").fadeIn(1000);
  196. $("#WeekStatisticsChart").find(".m-chart-title").append(": " + dateRangeStr);
  197. window.myBar = new Chart(ctx, {
  198. type: 'line',
  199. data: lineChartData,
  200. options: {
  201. responsive: true,
  202. maintainAspectRatio: false,
  203. legend: {
  204. position: 'top'
  205. },
  206. title: {
  207. display: true,
  208. text: LanguageDic['LB_STATISTICS_JOB_IN_WEEK']
  209. },
  210. scales: {
  211. xAxes: [{
  212. display: true,
  213. scaleLabel: {
  214. display: true,
  215. padding: 20,
  216. fontStyle: "bold",
  217. fontColor: "#ff1818",
  218. labelString: note
  219. }
  220. }],
  221. yAxes: [{
  222. ticks: {
  223. beginAtZero: true,
  224. //callback: function (value) { if (Number.isInteger(value)) { return value; } },
  225. //stepSize: 1
  226. },
  227. display: true,
  228. scaleLabel: {
  229. display: true,
  230. labelString: LanguageDic['LB_JOB_COUNT']
  231. }
  232. }]
  233. },
  234. //animation: {
  235. // duration: 1000,
  236. // onProgress: function (animation) {
  237. // progress.value = animation.currentStep / animation.numSteps;
  238. // },
  239. // onComplete: function () {
  240. // window.setTimeout(function () {
  241. // progress.value = 0;
  242. // }, 1000);
  243. // progress.className = "hidden";
  244. // }
  245. //}
  246. }
  247. });
  248. }
  249. function DrawAppWeekLineChart(rootData) {
  250. var DAYS = [
  251. LanguageDic['LB_DATE_MONDAY'],
  252. LanguageDic['LB_DATE_TUESDAY'],
  253. LanguageDic['LB_DATE_WEDNESDAY'],
  254. LanguageDic['LB_DATE_THUSDAY'],
  255. LanguageDic['LB_DATE_FRIDAY'],
  256. LanguageDic['LB_DATE_SATURDAY'],
  257. LanguageDic['LB_DATE_SUNDAY']
  258. ];
  259. //var progress = document.getElementById('animationProgress');
  260. var color = Chart.helpers.color;
  261. Chart.defaults.global.animation.duration = 3000;
  262. //var note = LanguageDic['LB_UPDATE'] + ': UPDATED_AT, ' + LanguageDic['LB_UPDATE_NEXT_TIME'] + ': UPDATE_NEXT';
  263. //note = note.replace('UPDATED_AT', rootData.UpdatedTime).replace('UPDATE_NEXT', rootData.NextUpdate);
  264. var note = LanguageDic['LB_DATA_DAILY_UPDATE_AUTO'];
  265. var dateRangeStr = rootData.FromDateStr + " - " + rootData.ToDateStr;
  266. var lineChartData = {
  267. labels: DAYS,
  268. datasets: [
  269. {
  270. label: LanguageDic['LB_APPLICATION_STATUS_AWAITING'] + ' (' + rootData.InWeekData.waitingTotal +')',
  271. backgroundColor: color(window.chartColors.orange).alpha(0.5).rgbString(),
  272. borderColor: window.chartColors.orange,
  273. borderWidth: 2,
  274. data: rootData.InWeekData.waitingData
  275. },
  276. {
  277. label: LanguageDic['LB_APPLICATION_STATUS_APPROVED'] + ' (' + rootData.InWeekData.approvedTotal + ')',
  278. backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
  279. borderWidth: 2,
  280. data: rootData.InWeekData.approvedData
  281. },
  282. {
  283. label: LanguageDic['LB_APPLICATION_STATUS_AGENCY_IGNORED'] + ' (' + rootData.InWeekData.ignoredTotal + ')',
  284. backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
  285. borderColor: window.chartColors.red,
  286. borderWidth: 2,
  287. data: rootData.InWeekData.ignoredData
  288. //hidden: true,
  289. }
  290. ]
  291. };
  292. var ctx = document.getElementById("AppWeekStatisticsChartCanvas").getContext("2d");
  293. $("#AppWeekStatisticsChart").fadeIn(1000);
  294. $("#AppWeekStatisticsChart").find(".m-chart-title").append(": " + dateRangeStr);
  295. window.myBar = new Chart(ctx, {
  296. type: 'bar',
  297. data: lineChartData,
  298. options: {
  299. responsive: true,
  300. maintainAspectRatio: false,
  301. legend: {
  302. position: 'top'
  303. },
  304. title: {
  305. display: true,
  306. text: LanguageDic['LB_STATISTICS_APP_IN_WEEK']
  307. },
  308. scales: {
  309. xAxes: [{
  310. display: true,
  311. scaleLabel: {
  312. display: true,
  313. padding: 20,
  314. fontStyle: "bold",
  315. fontColor: "#ff1818",
  316. labelString: note
  317. }
  318. }],
  319. yAxes: [{
  320. ticks: {
  321. beginAtZero: true,
  322. //callback: function (value) { if (Number.isInteger(value)) { return value; } }
  323. },
  324. display: true,
  325. scaleLabel: {
  326. display: true,
  327. labelString: LanguageDic['LB_APPLICATION_COUNT']
  328. }
  329. }]
  330. },
  331. //animation: {
  332. // duration: 1000,
  333. // onProgress: function (animation) {
  334. // progress.value = animation.currentStep / animation.numSteps;
  335. // },
  336. // onComplete: function () {
  337. // window.setTimeout(function () {
  338. // progress.value = 0;
  339. // }, 1000);
  340. // progress.className = "hidden";
  341. // }
  342. //}
  343. }
  344. });
  345. }