UNPKG

unserver-unify

Version:

261 lines (255 loc) 8.74 kB
'use strict'; angular.module('bamboo.common').controller('GameCtrl', function($scope, $filter, ApiService, UserService, loginService, $translate, schoolModel,userBizModel) { var self = this; this.defaultPersonPhotoUrl = "assets/images/default-person-icon.png"; this.imagePicUrl = ApiService.PSURL + "/avatar/"; function schoolApi(info, tab, callback) { ApiService.post('/schools', info).then(function(result) { if (result.data.success) { if (callback) { callback(result.data.data); } else { CommonService.showNoBlockSuccess('Update Successful!'); ApiService.getSchoolInfo().then(function() { _refreshSchoolInfo(); }); } } else { CommonService.showError("Update failed: " + result.data.error); } }); } function _refreshSchoolInfo() { ApiService.getSchoolInfo().then(function(school) { self.school = school; console.log(school); if (school.gameruledoc) { ApiService.get("/schooldoc/" + school.gameruledoc).then(function(result) { if (result.data.success && result.data.data) { self.ruledoc = result.data.data.content || {}; console.log(self.ruledoc); calcultScore(); } }); } }) } _refreshSchoolInfo(); loginService.getMyProfile(true).then(function(result) { console.log(result); $scope.user = result; }); // this.ruledoc={ // login:1, // usage:2, // level:5, // topic:5, // reply:5, // exam:10, // test:10, // assignment:10, // cert:100, // topuser:30, // }; // function getMedalByRank(rank) { var medal = 'medal01.png'; if (rank >= 0 && rank < 3) { medal = 'medal01.png'; } else if (rank >= 3 && rank < 9) { medal = 'medal02.png'; } else if (rank >= 9 && rank < 18) { medal = 'medal03.png'; } else if (rank >= 18 && rank < 30) { medal = 'medal11.png'; } else if (rank >= 30 && rank < 45) { medal = 'medal12.png'; } else if (rank >= 45 && rank < 63) { medal = 'medal13.png'; } else if (rank >= 63 && rank < 84) { medal = 'medal21.png'; } else if (rank >= 84 && rank < 108) { medal = 'medal22.png'; } else if (rank >= 108) { medal = 'medal31.png'; } return medal; } function getBadgeInfoByRank(rank) { var badges = self.ruledoc.badges; var badge = null angular.forEach(badges, function(val, idx) { if (rank <= val.max && rank >= val.min) { badge = val; } }); return badge; } function calExamCount(exam) { var res = 0; var keys = Object.keys(exam); angular.forEach(keys, function(val, idx) { res += exam[val]; }); return res; } function calcultScore() { loginService.getMyProfile(true).then(function(result) { console.log(result); result = result || {}; var loginDayCounter = result.loginDayCounter || 0; var totaltime = (result.totaltime || 0) / 3600; var summary = result.summary || {}; $scope.examCount = calExamCount(summary.exam); // console.log("summary", summary); // console.log("rule", self.ruledoc); // console.log("badges", self.ruledoc.badges); $scope.summary = summary; var exp = (self.ruledoc.assignment * summary.assignmentrecords) || 0 + (self.ruledoc.cert * summary.cert) || 0 + (self.ruledoc.attendance * summary.courseclass) || 0 + (self.ruledoc.login * loginDayCounter) + (self.ruledoc.usage * totaltime); var mastery = (self.ruledoc.gradeA * summary.exam.AF) || 0 + (self.ruledoc.gradeB * summary.exam.AP) || 0 + (self.ruledoc.gradeC * summary.exam.A) || 0 + (self.ruledoc.gradeD * summary.exam.B) || 0 + (self.ruledoc.gradeE * summary.exam.F) || 0 + (self.ruledoc.topuser * summary.topusser) || 0; var ctizship = (self.ruledoc.reply * summary.reply) || 0 + (self.ruledoc.topic * summary.topic) || 0; var score = exp + mastery + ctizship; //+ (self.ruledoc.exam * summary.examrecord) || 0 //+ (self.ruledoc.test * summary.testrecord) || 0 $scope.score = score || 0; //$scope.score = 3000; $scope.rank = Math.floor(Math.sqrt($scope.score + 0.25) - 0.5); $scope.medal = getMedalByRank($scope.rank); var badgeinfo = getBadgeInfoByRank($scope.score) || {}; console.log(badgeinfo, exp, score); $scope.badge = badgeinfo.name; $scope.exp = exp; $scope.expProgress = (score - badgeinfo.min) * (100.0) / badgeinfo.max; $scope.badgeMAX = badgeinfo.max; $scope.mastery = mastery; $scope.ctizship = ctizship; //console.info($scope.expProgress); }); } var footPrintKeyword = { "created": { "en": "You joined the bamboo", "cn": "加入九竹 ", "icon": "glyphicon-pushpin", "class": "info" }, "login": { "en": "You login for the first time ", "cn": "第一次登陆 ", "icon": "glyphicon-user", "class": "primary" }, "login100": { "en": "login more than 100 times ", "cn": "登陆超过100次", "icon": "glyphicon-user", "class": "success" }, "topic": { "en": "wrote your first topic ", "cn": "第一次在课程中发帖 ", "icon": "glyphicon-pencil", "class": "warning" }, "topic100": { "en": "You use 100 topics to express the desire for knowledge ", "cn": "你用100个话题表达对知识的渴望 ", "icon": "glyphicon-leaf", "class": "success" }, "reply": { "en": "reply your classmates the first time ", "cn": "第一次在论坛回复同学 ", "icon": "glyphicon-edit", "class": "danger" }, "bbs": { "en": "wrote your first bbs post ", "cn": "第一次在论坛发帖 ", "icon": "glyphicon-pencil", "class": "warning" }, "bbsreply": { "en": "The first time you Replied, to say hello to your classmates ", "cn": "第一次回帖,向同学问好 ", "icon": "glyphicon-pencil", "class": "warning" }, "blog": { "en": "post a blog for the first time, sharing knowledge with the world ", "cn": "第一次发表博客,与世界分享知识 ", "icon": "glyphicon-pencil", "class": "warning" }, "exam": { "en": "take the exam for the first time ", "cn": "第一次参加考试 ", "icon": "glyphicon-edit", "class": "info" }, "assignment": { "en": "do your homework for the first time ", "cn": "第一次做作业 ", "icon": "glyphicon-pencil", "class": "warning" }, "attend": { "en": "sign in for the first time ", "cn": "第一次签到 ", "icon": "glyphicon-ok-circle", "class": "success" }, "hour": { "en": "online for 1 hour ", "cn": "在线满1小时 ", "icon": "glyphicon-sunglasses", "class": "info" }, "hour10": { "en": "online for 10 hours ", "cn": "在线满10小时 ", "icon": "glyphicon-sunglasses", "class": "info" }, "fullexam": { "en": "got a full mark in the exam for the first time", "cn": "第一次在考试中得满分", "icon": "glyphicon-thumbs-up", "class": "success" } }; //get foot print var info = { action: 'getmyfootprint', } UserService.UserApi(info, function(result) { console.log($translate.use()); var isEngLang = $translate.use().indexOf('en') > -1; console.log(isEngLang); console.log(result); var keys = Object.keys(result); console.log(keys); keys.splice(keys.indexOf('_id'), 1); keys.splice(keys.indexOf('__v'), 1); console.log(keys); var events = []; angular.forEach(keys, function(val, idx) { //console.log(val); if (footPrintKeyword[val]) { events.push({ time: $filter('date')(result[val], "dd/MM/yyyy"), name: val, badgeClass: footPrintKeyword[val].class, badgeIconClass: footPrintKeyword[val].icon, title: isEngLang ? footPrintKeyword[val].en : footPrintKeyword[val].cn, content: $filter('date')(result[val], "dd-MM-yyyy") }); }   }); events.sort(function(a, b) { return (new Date(a.time).getTime()) - (new Date(b.time).getTime()); }); console.table(events); $scope.events = events; }); });