knowledgeCtrl.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  1. app.controller('knowledgeManagerCtrl', ["$rootScope", "$scope", "i18nService", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_solution", "api_bpm_domain", function($rootScope, $scope, i18nService, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_solution, api_bpm_domain) {
  2. $scope.langs = i18nService.getAllLangs();
  3. $scope.lang = 'zh-cn';
  4. i18nService.setCurrentLang($scope.lang);
  5. var loginUser = $rootScope.user;
  6. // console.log(' loginUser='+JSON.stringify( loginUser));
  7. //for test
  8. // loginUser = {
  9. // id:2,
  10. // name:'李进'
  11. // };
  12. //console.log(loginUser);
  13. $scope.gridOptions = {};
  14. $scope.gridOptions.data = 'myData';
  15. $scope.gridOptions.enableColumnResizing = true;
  16. $scope.gridOptions.enableFiltering = false;
  17. $scope.gridOptions.enableGridMenu = false;
  18. $scope.gridOptions.enableRowSelection = true;
  19. $scope.gridOptions.showGridFooter = true;
  20. $scope.gridOptions.showColumnFooter = false;
  21. $scope.gridOptions.fastWatch = true;
  22. $scope.gridOptions.useExternalPagination = true;
  23. $scope.gridOptions.paginationPageSizes = [10];
  24. $scope.gridOptions.paginationPageSize = 10;
  25. $scope.gridOptions.multiSelect = false;
  26. $scope.gridOptions.rowIdentity = function(row) {
  27. return row.id;
  28. };
  29. $scope.gridOptions.getRowIdentity = function(row) {
  30. return row.id;
  31. };
  32. $scope.transferTime = function(time) {
  33. return moment(time).format('YYYY-MM-DD ');
  34. }
  35. $scope.transferStatus = function(status) {
  36. var statusLabel = "不合法的状态";
  37. if (status == 1) {
  38. statusLabel = "待审核";
  39. } else if (status == 2) {
  40. statusLabel = "已批准";
  41. } else if (status == 3) {
  42. statusLabel = "已发布";
  43. } else if (status == 4) {
  44. statusLabel = "已取消";
  45. } else if (status == 5) {
  46. statusLabel = "已驳回";
  47. } else if (status == 6) {
  48. statusLabel = "已拒绝";
  49. }
  50. return statusLabel;
  51. }
  52. // $scope.myDD={
  53. // 'solutionNumber':'编号',
  54. // 'typeName':'类别',
  55. // 'title':'标题',
  56. // 'keywords':'关键字',
  57. // 'status':'状态',
  58. // 'createUserName':'创建人',
  59. // 'createtime':'创建日期',
  60. // '操作':'操作'
  61. // }
  62. $scope.gridOptions.columnDefs = [
  63. { name: 'solutionNumber', displayName: '编号', width: 100 },
  64. { name: 'typeName', displayName: '类别', width: 100 },
  65. { name: 'title', displayName: '标题', width: 100 },
  66. { name: 'keywords', displayName: '关键字', width: 100 },
  67. { name: 'status', displayName: '状态', cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferStatus(row.entity.status)}}</div>', width: 80 },
  68. { name: 'createUserName', displayName: '创建人', width: 60 },
  69. { name: 'createtime', cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.transferTime(row.entity.createtime)}}</div>', displayName: '创建日期', width: 100 },
  70. { name: '操作', cellTemplate: '<gridoperator item="row.entity" colobject="col">' }
  71. ];
  72. $scope.gridOptions.onRegisterApi = function(gridApi) {
  73. $scope.gridApi = gridApi;
  74. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
  75. var filtersData = $scope.allfilterData;
  76. // console.log(filtersData)
  77. filterData.pageIndex = newPage - 1;
  78. var data = { pageIndex: newPage - 1 };
  79. var dataFilter = angular.extend(data, filterData);
  80. dataFilter.status = filtersData.status;
  81. // console.log(dataFilter)
  82. $scope.refreshListData('expand-right', dataFilter);
  83. });
  84. gridApi.selection.on.rowSelectionChanged($scope, function(data) {
  85. $scope.selected.item = data.entity;
  86. });
  87. };
  88. this.selectRowFunction = function(data) {};
  89. $scope.refreshListData = function(style, filterData) {
  90. $scope.ldloading[style.replace('-', '_')] = true;
  91. if (angular.isUndefined(filterData)) {
  92. filterData = defaultFilterData;
  93. }
  94. if (angular.isDefined($scope.searchTypes)) {
  95. filterData['searchType'] = $scope.searchTypes;
  96. }
  97. $scope.myData = [];
  98. api_solution.findSolutionByKeys(filterData).then(function(data) {
  99. var myData = Restangular.stripRestangular(data);
  100. // console.log("myData="+JSON.stringify(myData));
  101. $scope.gridOptions.totalItems = myData.totalNum;
  102. if (angular.isArray(myData.list)) {
  103. $scope.myData = myData.list;
  104. } else {
  105. SweetAlert.swal({
  106. title: "数据为空",
  107. text: myData.list,
  108. type: "warning"
  109. });
  110. }
  111. $scope.ldloading[style.replace('-', '_')] = false;
  112. }, function() {
  113. $scope.ldloading[style.replace('-', '_')] = false;
  114. });
  115. }
  116. $scope.createKnowledge = function() {
  117. var data = { model: { knowledge: { createUserId: loginUser.id, status: 1 } } };
  118. $state.go('app.knowledge.create', { formKey: 'knowledge_create', service: 'api_solution', 'model': JSON.stringify(data) })
  119. }
  120. $scope.detailSolution = function(id) {
  121. api_solution.findSolutionById(id).then(function(response) {
  122. var data = { model: { knowledge: response.data } };
  123. if (!isNaN(data.model.knowledge.vision)) {
  124. data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
  125. }
  126. $state.go('app.knowledge.detail', { formKey: 'knowledge_detail', service: 'api_solution', 'model': JSON.stringify(data) })
  127. })
  128. }
  129. $scope.editSolution = function(id) {
  130. api_solution.findSolutionById(id).then(function(response) {
  131. var data = { model: { knowledge: response.data } };
  132. if (!isNaN(data.model.knowledge.vision)) {
  133. data.model.knowledge.vision = 'V' + String(data.model.knowledge.vision);
  134. }
  135. $state.go('app.knowledge.editor', { formKey: 'knowledge_editor', service: 'api_solution', 'model': JSON.stringify(data) })
  136. })
  137. }
  138. $scope.commentSolution = function(id) {
  139. var modalInstance = $modal.open({
  140. templateUrl: 'assets/views/knowledge/tpl/commentknowledge.html',
  141. controller: function($scope, $http, $modalInstance, APIService, uploader, currentUser, Alert, MomentFormat) {
  142. $scope.uploader = uploader;
  143. var loadData = function() {
  144. $scope.visions = [];
  145. $scope.entity = {};
  146. $scope.solutionDowpath = APIService.getSolutionDowpath().getRequestedUrl();
  147. APIService.findSolutionById(id).then(function(response) {
  148. var data = response.data;
  149. console.log(data);
  150. $scope.entity = {
  151. "id": data.id,
  152. "title": data.title,
  153. "keys": data.keywords,
  154. "type": data.typeId,
  155. "range": data.solutionRange,
  156. "number": data.solutionNumber,
  157. "content": data.content,
  158. "createrUserId": data.createrUserId,
  159. "createrUserName": data.createrUserName,
  160. "createTime": data.createtime,
  161. "status": data.status,
  162. "hits": data.hits,
  163. "relateId": data.relateId,
  164. "vision": data.vision,
  165. "vision2": "V" + data.vision,
  166. "fileContent": data.fileContent,
  167. "replies": data.replies,
  168. "scores": data.scores,
  169. "hits": data.hits,
  170. "fileName": data.fileName,
  171. "typeName": data.typeDTO.typeName
  172. };
  173. $scope.file = data.fileName;
  174. $scope.nowEntity = data;
  175. $scope.couldReview = true;
  176. $scope.showOutTime = true;
  177. if ($scope.nowEntity.status != 1) { //状态只有是 待审核状态 才能进行审核
  178. $scope.couldReview = false;
  179. }
  180. if (($scope.nowEntity.status == 2) && outtime) { //表示状态为已通过
  181. $scope.showOutTime = false;
  182. }
  183. $scope.showCommentScore = true;
  184. $scope.comments = [];
  185. APIService.findSolutionReviewById(loginUser.id, data.id, 0, 1000).then(function(response) {
  186. if (response.status != "500") {
  187. var data = response.list;
  188. // console.log("data="+data);
  189. if (angular.isDefined(response.result)) { $scope.showCommentScore = false; }
  190. for (var i = 0; i < data.length; i++) {
  191. var object = {};
  192. object.id = data[i].id;
  193. object.name = data[i].userName;
  194. // object.content=data[i].review;
  195. var ss = data[i].review;
  196. var s1 = "";
  197. if (ss != null) {
  198. var index = ss.indexOf("<p>");
  199. var indexs = ss.indexOf("</p>");
  200. s1 = ss.substring(index + 3, indexs);
  201. }
  202. object.content = s1;
  203. object.score = data[i].reviewScore;
  204. object.time = MomentFormat(data[i].reviewTime).format('YYYY-MM-DD ');
  205. // console.log("object="+object );
  206. $scope.comments.push(object);
  207. }
  208. }
  209. });
  210. });
  211. }
  212. loadData();
  213. $scope.options = {
  214. language: 'zh-cn',
  215. allowedContent: true,
  216. entities: false
  217. };
  218. $scope.uploader = uploader;
  219. $scope.onReady = function() {
  220. // ...
  221. };
  222. $scope.getdown = function(filename) {
  223. $http({
  224. url: APIService.getSolutionDowpath(id).getRequestedUrl(),
  225. method: 'GET',
  226. headers: {
  227. //'Content-type' : 'application/xls',
  228. 'Accept': '*/*'
  229. },
  230. responseType: 'arraybuffer'
  231. }).success(function(data, status, headers, config) {
  232. var file = new Blob([data], {
  233. type: 'application/octet-stream'
  234. });
  235. //trick to download store a file having its URL
  236. var fileURL = URL.createObjectURL(file);
  237. var a = document.createElement('a');
  238. a.href = fileURL;
  239. a.target = '_blank';
  240. a.download = filename;
  241. document.body.appendChild(a);
  242. a.click();
  243. }).error(function(data, status, headers, config) {
  244. console.log(data);
  245. });
  246. }
  247. $scope.ranges = [{
  248. "id": 1,
  249. "name": "全局"
  250. }, {
  251. "id": 3,
  252. "name": "组"
  253. }];
  254. $scope.cancel = function() {
  255. $modalInstance.dismiss('cancel');
  256. };
  257. $scope.saveComment = function(reviewcontent, score) {
  258. $scope.entity['reviewcontent'] = reviewcontent;
  259. $scope.entity['score'] = score;
  260. $modalInstance.close($scope.entity);
  261. }
  262. },
  263. size: 'lg',
  264. resolve: {
  265. APIService: function() {
  266. return api_solution;
  267. },
  268. uploader: function() {
  269. return $scope.uploader;
  270. },
  271. currentUser: function() {
  272. return loginUser.id;
  273. },
  274. Alert: function() {
  275. return SweetAlert;
  276. },
  277. MomentFormat: function() {
  278. return moment;
  279. }
  280. }
  281. });
  282. modalInstance.result.then(function(selectedItem) {
  283. console.log('selectedItem=' + JSON.stringify(selectedItem));
  284. // console.log('reviewContent='+JSON.stringify(reviewContent));
  285. // console.log('score='+JSON.stringify(score));
  286. if (selectedItem) {
  287. var solutionId = selectedItem.id;
  288. var reviewContent = selectedItem.reviewcontent;
  289. // if(solutionId==null){
  290. var reviewScore
  291. if (selectedItem.score) { reviewScore = selectedItem.score.toFixed(1) }
  292. var data = {
  293. id: null,
  294. solutionId: solutionId,
  295. userId: loginUser.id,
  296. review: reviewContent,
  297. reviewScore: reviewScore,
  298. reviewTime: new Date()
  299. };
  300. api_solution.addSolutionReview(data).then(function(response) {
  301. var status = response.status;
  302. console.log(response)
  303. console.log('$scope.apClient=' + JSON.stringify(status));
  304. if (status == "200") {
  305. // var data=response.data;
  306. // $scope.reviewcontent="";
  307. // $scope.score=0;
  308. SweetAlert.swal({
  309. title: "评论知识库!",
  310. text: "评论知识库成功!",
  311. type: "success"
  312. }, function() {
  313. $scope.reload();
  314. });
  315. } else {
  316. SweetAlert.swal({
  317. title: "评论知识库!",
  318. text: "评论知识库失败!",
  319. type: "error"
  320. });
  321. }
  322. });
  323. }
  324. });
  325. }
  326. $scope.approvalSolution = function(id, outTimePower) {
  327. var modalInstance = $modal.open({
  328. templateUrl: 'assets/views/knowledge/tpl/approvalknowledge.html',
  329. controller: function($scope, $modalInstance, APIService, Alert, workGroups, uploader, tree_data, outTimePower) {
  330. $scope.wgroups = workGroups;
  331. $scope.type_handler = function(branch) {
  332. $scope.typeIds = branch.id;
  333. // console.log(branch);
  334. };
  335. $scope.type_data = tree_data;
  336. $scope.uploader = uploader;
  337. var loadData = function() {
  338. $scope.visions = [];
  339. APIService.findSolutionById(id).then(function(response) {
  340. var data = response.data;
  341. $scope.visions = data;
  342. $scope.entity = {
  343. "id": data.id,
  344. "title": data.title,
  345. "keys": data.keywords,
  346. "typeId": data.typeId,
  347. "range": data.solutionRange,
  348. "number": data.solutionNumber,
  349. "content": data.content,
  350. "createrUserId": data.createrUserId,
  351. "createrUserName": data.createrUserName,
  352. "createTime": data.createTime,
  353. "status": data.status,
  354. "hits": data.hits,
  355. "relateId": data.relateId,
  356. "vision": data.vision,
  357. "outtime": outTimePower,
  358. // "filePic":$scope.filePic,
  359. "typeName": data.typename,
  360. "fileName": data.fileName
  361. };
  362. $scope.nowEntity = data;
  363. $scope.couldReview = true;
  364. $scope.showOutTime = true;
  365. $scope.fabu = false;
  366. $scope.shenhe = false;
  367. $scope.fabulabel = false;
  368. $scope.chexiao = false;
  369. $scope.shouquan = false;
  370. if ($scope.nowEntity.status != 1) { //状态只有是 待审核状态 才能进行审核
  371. $scope.couldReview = false;
  372. }
  373. if ($scope.nowEntity.status == 1) {
  374. $scope.shenhe = true;
  375. if ($scope.entity.range == 3) {
  376. $scope.shouquan = true;
  377. $scope.multipleDemo = {};
  378. }
  379. }
  380. if ($scope.nowEntity.status == 2) {
  381. $scope.fabu = true;
  382. $scope.fabulabel = true;
  383. }
  384. if ($scope.nowEntity.status == 3) {
  385. $scope.fabu = false;
  386. $scope.chexiao = true;
  387. $scope.showOutTime = false;
  388. }
  389. if (($scope.nowEntity.status == 2) && outTimePower) { //表示状态为已通过
  390. $scope.showOutTime = false;
  391. }
  392. });
  393. }
  394. $scope.closeAlert = function(index) {
  395. $scope.alerts.splice(index, 1);
  396. };
  397. $scope.test = false;
  398. $scope.getin = false;
  399. $scope.verifySolutions = function(type, reason) {
  400. var publishRange = angular.element("#publishRange").val();
  401. if (publishRange == "") {
  402. publishRange = 0;
  403. }
  404. var status = "";
  405. var statusName = "";
  406. if (type == "success") { //审核通过
  407. status = 2;
  408. statusName = "审核通过";
  409. } else if (type == "failed") { //审核驳回
  410. status = 5;
  411. statusName = "审核驳回";
  412. } else if (type == "reject") { //审核拒绝
  413. status = 6;
  414. statusName = "审核拒绝";
  415. } else if (type == "outtime") { //过时
  416. status = 4;
  417. statusName = "取消";
  418. } else if (type = "publish") { //发布
  419. status = 3;
  420. statusName = "发布";
  421. }
  422. $scope.entity.status = status;
  423. $scope.entity['statusName'] = statusName;
  424. $scope.entity['reason'] = reason;
  425. $modalInstance.close($scope.entity);
  426. };
  427. $scope.group = [];
  428. api_user_data.fetchDataList('group', { 'idx': 0, 'sum': 1000 }).then(function(result) {
  429. $scope.my_data = convertParentToChildList(result['list']);
  430. var nata = [];
  431. for (var i = 0; i < $scope.my_data.length; i++) {
  432. nata.push({
  433. 'groupname': $scope.my_data[i].groupName,
  434. 'id': $scope.my_data[i].id
  435. })
  436. $scope.group = nata;
  437. }
  438. })
  439. $scope.saveright = function(multipleDemo) {
  440. console.log(multipleDemo);
  441. $scope.entity['multipleDemo'] = multipleDemo;
  442. }
  443. $scope.options = {
  444. language: 'zh-cn',
  445. allowedContent: true,
  446. entities: false
  447. };
  448. $scope.onReady = function() {
  449. // ...
  450. };
  451. $scope.ranges = [{
  452. "id": 1,
  453. "name": "全局"
  454. }, {
  455. "id": 3,
  456. "name": "组"
  457. }];
  458. $scope.cancel = function() {
  459. $modalInstance.dismiss('cancel');
  460. };
  461. loadData();
  462. },
  463. size: 'lg',
  464. resolve: {
  465. APIService: function() {
  466. return api_solution;
  467. },
  468. Alert: function() {
  469. return SweetAlert;
  470. },
  471. workGroups: function() {
  472. return $scope.groups;
  473. },
  474. uploader: function() {
  475. return $scope.uploader;
  476. },
  477. tree_data: function() {
  478. return angular.copy($scope.tree_data);
  479. },
  480. outTimePower: function() {
  481. return outTimePower;
  482. }
  483. }
  484. });
  485. modalInstance.result.then(function(selectedItem) {
  486. if (selectedItem) {
  487. console.log(selectedItem);
  488. if (selectedItem.status == 2 && selectedItem.range == 3) {
  489. console.log(selectedItem.multipleDemo.item);
  490. if (angular.isUndefined(selectedItem.multipleDemo.item) || selectedItem.multipleDemo.item == "") {
  491. SweetAlert.swal({
  492. title: "授权为空",
  493. text: "请选择本知识授权组",
  494. type: "error"
  495. });
  496. } else {
  497. var item = [];
  498. for (var i = 0; i < selectedItem.multipleDemo.item.length; i++) {
  499. item[i] = selectedItem.multipleDemo.item[i].id;
  500. }
  501. api_solution.saveSolutionGroup(selectedItem.id, item).then(function(response) {
  502. $scope.data4 = response;
  503. if ($scope.data4.status == "200") {
  504. var filedata = { solution: { id: selectedItem.id, status: selectedItem.status, renewUserId: loginUser.id, publishrange: 0, reject: selectedItem.reason } }
  505. api_solution.updateSolutionStatus(filedata).then(function(response) {
  506. $scope.data5 = response;
  507. console.log($scope.data4);
  508. console.log($scope.data4)
  509. if ($scope.data5.status == "200") {
  510. SweetAlert.swal({
  511. title: "审核知识库",
  512. text: '审核成功',
  513. type: "warning"
  514. }, function() {
  515. $scope.reload();
  516. });
  517. } else {
  518. SweetAlert.swal({
  519. title: "审核知识库",
  520. text: '审核失败',
  521. type: "warning"
  522. });
  523. }
  524. });
  525. } else {
  526. SweetAlert.swal({
  527. title: "授权",
  528. text: '授权失败',
  529. type: "warning"
  530. });
  531. }
  532. });
  533. }
  534. } else {
  535. var filedata = { solution: { id: selectedItem.id, status: selectedItem.status, renewUserId: loginUser.id, publishrange: 0, reject: selectedItem.reason } }
  536. api_solution.updateSolutionStatus(filedata).then(function(response) {
  537. console.log(response);
  538. var status = response.status;
  539. if (response.status == "200") {
  540. // if(status=="200"){
  541. SweetAlert.swal({
  542. title: selectedItem.statusName + "知识库",
  543. text: selectedItem.statusName + '成功',
  544. type: "warning"
  545. }, function() {
  546. $scope.reload();
  547. });
  548. } else {
  549. SweetAlert.swal({
  550. title: statusName + "知识库",
  551. text: statusName + '失败',
  552. type: "warning"
  553. });
  554. }
  555. });
  556. }
  557. }
  558. })
  559. }
  560. $scope.publishSolution = function(id, outTimePower) {
  561. var modalInstance = $modal.open({
  562. templateUrl: 'assets/views/knowledge/tpl/publishknowledge.html',
  563. controller: function($scope, $modalInstance, APIService, Alert, workGroups, uploader, outTimePower) {
  564. $scope.group = [];
  565. api_user_data.fetchDataList('group', { 'idx': 0, 'sum': 1000 }).then(function(result) {
  566. $scope.my_data = convertParentToChildList(result['list']);
  567. var nata = [];
  568. for (var i = 0; i < $scope.my_data.length; i++) {
  569. nata.push({
  570. 'groupname': $scope.my_data[i].groupName,
  571. 'id': $scope.my_data[i].id
  572. })
  573. $scope.group = nata;
  574. }
  575. })
  576. $scope.options = {
  577. language: 'zh-cn',
  578. allowedContent: true,
  579. entities: false
  580. };
  581. $scope.onReady = function() {
  582. // ...
  583. };
  584. $scope.ranges = [{
  585. "id": 1,
  586. "name": "全局"
  587. }, {
  588. "id": 3,
  589. "name": "组"
  590. }];
  591. $scope.ok = function() {
  592. var data = {};
  593. $modalInstance.close($scope.entity);
  594. };
  595. $scope.cancel = function() {
  596. $modalInstance.dismiss('cancel');
  597. };
  598. loadData();
  599. },
  600. size: 'lg',
  601. resolve: {
  602. APIService: function() {
  603. return api_solution;
  604. },
  605. Alert: function() {
  606. return SweetAlert;
  607. },
  608. workGroups: function() {
  609. return $scope.groups;
  610. },
  611. uploader: function() {
  612. return $scope.uploader;
  613. },
  614. tree_data: function() {
  615. return angular.copy($scope.tree_data);
  616. },
  617. outTimePower: function() {
  618. return outTimePower;
  619. }
  620. }
  621. });
  622. }
  623. var apple_selected, tree, treedata_avm, treedata_geography;
  624. //$scope.selectedTreeNode = {};
  625. $scope.my_tree_handler = function(branch) {
  626. filterData.treeIds = branch.id;
  627. $scope.selectedTreeNode = branch;
  628. $scope.refreshListData('expand-right', filterData);
  629. };
  630. $scope.my_data = [];
  631. $scope.tree_data = [];
  632. $scope.my_tree = tree = {};
  633. function convertListToTree(data, treeMap) {
  634. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  635. var root = null; //Initially set our loop to null
  636. var parentNode = null;
  637. //loop over data
  638. for (var i = 0; i < data.length; i++) {
  639. var datum = data[i];
  640. //each node will have children, so let's give it a "children" poperty
  641. datum.children = [];
  642. //add an entry for this node to the map so that any future children can
  643. //lookup the parent
  644. idToNodeMap[datum.id] = datum;
  645. //Does this node have a parent?
  646. if (typeof datum.parent === "undefined" || datum.parent == null) {
  647. //Doesn't look like it, so this node is the root of the tree
  648. root = datum;
  649. treeMap[datum.id] = root;
  650. } else {
  651. //This node has a parent, so let's look it up using the id
  652. parentNode = idToNodeMap[datum.parent];
  653. //We don't need this property, so let's delete it.
  654. delete datum.parent;
  655. //Let's add the current node as a child of the parent node.
  656. parentNode.children.push(datum);
  657. }
  658. }
  659. return root;
  660. }
  661. function convertParentToChildList(data) {
  662. var treeMap = {};
  663. var list = [];
  664. convertListToTree(data, treeMap);
  665. angular.forEach(treeMap, function(item) {
  666. list.push(item);
  667. });
  668. return list;
  669. }
  670. var uploader = $scope.uploader = new FileUploader({
  671. url: api_solution.upload().getRequestedUrl(),
  672. alias: "file",
  673. removeAfterUpload: true,
  674. queueLimit: 10
  675. // headers : {
  676. // }
  677. });
  678. $scope.removeKnowledgeType = function() {
  679. var b = $scope.my_tree.get_selected_branch();
  680. if (b != null) {
  681. SweetAlert.swal({
  682. title: "确认删除?",
  683. text: "删除数据后,将不能恢复该数据!",
  684. type: "warning",
  685. cancelButtonText: "取消",
  686. showCancelButton: true,
  687. confirmButtonColor: "#DD6B55",
  688. confirmButtonText: "确认删除!"
  689. }, function(isConfirm) {
  690. if (isConfirm) {
  691. api_solution.removeSolutionType(b.id).then(function(response) {
  692. if (response.status == 204) {
  693. $scope.try_async_load();
  694. SweetAlert.swal({
  695. title: "删除成功!",
  696. confirmButtonColor: "#007AFF"
  697. });
  698. } else {
  699. SweetAlert.swal({
  700. title: "删除失败!",
  701. text: response.data,
  702. confirmButtonColor: "#007AFF"
  703. });
  704. }
  705. });
  706. }
  707. });
  708. } else {
  709. SweetAlert.swal({
  710. title: "删除数据错误",
  711. text: "无法删除,请选中一个知识库类型!",
  712. type: "warning"
  713. });
  714. }
  715. }
  716. $scope.editKnowledgeType = function(flag, size) {
  717. var modalInstance = $modal.open({
  718. templateUrl: 'assets/views/knowledge/tpl/newknowledgetype.html',
  719. controller: function($scope, $modalInstance, selectNode, parentNode, isCreate, Alert) {
  720. $scope.editNode = {};
  721. if (angular.isDefined(selectNode)) {
  722. $scope.editNode.id = selectNode.id;
  723. $scope.editNode.typeName = selectNode.label;
  724. }
  725. if (angular.isDefined(parentNode) && (parentNode != null)) {
  726. $scope.editNode.pid = parentNode.id;
  727. $scope.parentName = parentNode.label;
  728. $scope.ok = function() {
  729. var data = {};
  730. if (isCreate) {
  731. data = {
  732. flag: isCreate,
  733. typeName: $scope.editNode.typeName,
  734. pid: $scope.editNode.pid
  735. }
  736. } else {
  737. data = {
  738. flag: isCreate,
  739. id: $scope.editNode.id,
  740. typeName: $scope.editNode.typeName,
  741. pid: $scope.editNode.pid
  742. }
  743. }
  744. $modalInstance.close(data);
  745. };
  746. } else {
  747. Alert.swal({
  748. title: "操作错误",
  749. text: "请选择要添加类别的父类!",
  750. type: "warning"
  751. })
  752. return undefined;
  753. }
  754. $scope.ok = function() {
  755. $modalInstance.close($scope.entity);
  756. };
  757. $scope.cancel = function() {
  758. $modalInstance.dismiss('cancel');
  759. };
  760. },
  761. size: size,
  762. resolve: {
  763. selectNode: function() {
  764. if (!flag) {
  765. return $scope.my_tree.get_selected_branch();
  766. } else {
  767. return undefined;
  768. }
  769. },
  770. parentNode: function() {
  771. if (flag) {
  772. return $scope.my_tree.get_selected_branch();
  773. } else {
  774. var b = $scope.my_tree.get_selected_branch();
  775. if (b != null) {
  776. return $scope.my_tree.get_parent_branch(b);
  777. }
  778. return undefined;
  779. }
  780. },
  781. isCreate: function() {
  782. return flag;
  783. },
  784. Alert: function() {
  785. return SweetAlert;
  786. }
  787. }
  788. });
  789. modalInstance.result.then(function(selectedItem) {
  790. if (selectedItem) {
  791. if (selectedItem.flag) {
  792. api_solution.addSolutionType({ "pid": selectedItem.pid, "typeName": selectedItem.typeName }).then(function(response) {
  793. var myData = Restangular.stripRestangular(response);
  794. var data = myData.data;
  795. if (myData.status == 201) {
  796. $scope.try_async_load();
  797. SweetAlert.swal({
  798. title: "操作成功",
  799. text: "操作成功!",
  800. type: "success"
  801. });
  802. }
  803. })
  804. } else {
  805. api_solution.updateSolutionType({ "id": selectedItem.id, "pid": selectedItem.pid, "typeName": selectedItem.typeName }).then(function(response) {
  806. var myData = Restangular.stripRestangular(response);
  807. var data = myData.data;
  808. if (myData.status == 201) {
  809. $scope.try_async_load();
  810. SweetAlert.swal({
  811. title: "操作成功",
  812. text: "操作成功!",
  813. type: "success"
  814. });
  815. }
  816. })
  817. }
  818. }
  819. });
  820. }
  821. $scope.my_tree = tree = {};
  822. $scope.try_async_load = function() {
  823. $scope.my_data = [];
  824. $scope.doing_async = true;
  825. api_user_data.fetchDataList('group', { "idx": 0, "sum": 1000 }).then(function(response) {
  826. var myData = Restangular.stripRestangular(response);
  827. var list = myData.list;
  828. var objects = [];
  829. for (var i = 0; i < list.length; i++) {
  830. var object = {};
  831. object.id = list[i].id;
  832. if (list[i].parent == 0) {
  833. object.parent = "#";
  834. } else {
  835. object.parent = list[i].parent;
  836. }
  837. object.text = list[i].groupName;
  838. object.typeName = "group";
  839. object.state = {
  840. "opened": true
  841. };
  842. objects.push(object);
  843. }
  844. $scope.groups = objects;
  845. });
  846. api_solution.findSolutionTypeActions(loginUser.id).then(function(response) {
  847. if (response.status == 200) {
  848. var data = response.data;
  849. // console.log('data='+JSON.stringify(data));
  850. var objects = [];
  851. for (var i = 0; i < data.length; i++) {
  852. var object = {};
  853. object.id = data[i].id;
  854. if (data[i].pid != 0) {
  855. object.parent = data[i].pid;
  856. }
  857. // if (object.parent == 0) {
  858. // object.parent = "#";
  859. // }
  860. object.label = data[i].typeName;
  861. object.actions = data[i].actions; //权限部分
  862. object.group = "1";
  863. object.user = "2";
  864. object.state = {
  865. "opened": true
  866. };
  867. object.typeName = "type";
  868. objects.push(object);
  869. }
  870. $scope.my_data = convertParentToChildList(objects);
  871. $scope.tree_data = angular.copy($scope.my_data);
  872. if ($scope.my_data.length > 0) {
  873. $scope.doing_async = false;
  874. }
  875. } else {
  876. SweetAlert.swal({
  877. title: "系统错误!",
  878. text: "请刷新重试!",
  879. type: "error"
  880. });
  881. }
  882. });
  883. $scope.showAddSolutionType = false; //添加知识类型 按钮
  884. $scope.showReviewKnowledgeType = false; //审核知识类型 按钮
  885. };
  886. $scope.try_async_load();
  887. $scope.ldloading = {};
  888. $scope.allfilterData = {
  889. key: 'null',
  890. status: 0,
  891. pageIndex: 0,
  892. pageSum: 10,
  893. //treeIds:'[]',
  894. userId: loginUser.id
  895. }
  896. var filterData = {
  897. key: 'null',
  898. status: 0,
  899. pageIndex: 0,
  900. pageSum: 10,
  901. //treeIds:'[]',
  902. userId: loginUser.id
  903. }
  904. $scope.statuses = [
  905. { status: 1, label: '待审核' },
  906. { status: 2, label: '已批准' },
  907. { status: 3, label: '已发布' },
  908. { status: 4, label: '已取消' },
  909. { status: 5, label: '已驳回' },
  910. { status: 6, label: '已拒绝' }
  911. ];
  912. $scope.$watch('searchSolutionInput', function(oldvalue, newvalue) {
  913. // console.log(' oldvalue='+JSON.stringify( oldvalue));
  914. // console.log(' newvalue='+JSON.stringify( newvalue));
  915. // if(oldvalue==newvalue) return;
  916. if (angular.isUndefined(oldvalue) || oldvalue == '') {
  917. filterData.key = 'null';
  918. } else {
  919. filterData.key = oldvalue;
  920. }
  921. });
  922. $scope.people = [
  923. { name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States' },
  924. { name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina' },
  925. { name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina' },
  926. { name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador' },
  927. { name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador' },
  928. { name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States' },
  929. { name: 'Nicole', email: 'nicole@email.com', age: 43, country: 'Colombia' },
  930. { name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador' },
  931. { name: 'Michael', email: 'michael@email.com', age: 15, country: 'Colombia' },
  932. { name: 'Nicolás', email: 'nicolas@email.com', age: 43, country: 'Colombia' }
  933. ];
  934. $scope.searchSolution = function() {
  935. $scope.refreshListData('expand-right', filterData);
  936. }
  937. $scope.reload = function() {
  938. if ($rootScope.searchknowledge) { filterData = $rootScope.searchknowledge; }
  939. $scope.refreshListData('expand-right', filterData);
  940. }
  941. $scope.reload();
  942. }]);
  943. app.controller('knowledgeForumCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "moment", "Restangular", "api_solution", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, moment, Restangular, api_solution) {
  944. var loginUser = $rootScope.user;
  945. $scope.clses = [{
  946. id: 6,
  947. cls: 'danger'
  948. }, {
  949. id: 2,
  950. cls: 'warning'
  951. }, {
  952. id: 3,
  953. cls: 'success'
  954. },
  955. {
  956. id: 4,
  957. cls: 'primary'
  958. }, {
  959. id: 5,
  960. cls: 'info'
  961. }, {
  962. id: 1,
  963. cls: 'danger'
  964. }
  965. ];
  966. $scope.showlist = true;
  967. $scope.searchSolution = function(searchKey, page) {
  968. console.log(page)
  969. $scope.getKnowledgeList();
  970. if (searchKey == "") {
  971. ng - u
  972. if (angular.isDefined(page)) {
  973. if (page == 0) {
  974. page = 1;
  975. } else if (page == $scope.pages + 1) {
  976. page = $scope.pages;
  977. }
  978. } else {
  979. tempPage = page = 0;
  980. $scope.solutionBBS = [];
  981. }
  982. api_solution.queryBBSSolutions(tempPage, 7, 'createtime', loginUser.id, searchKey).then(function(response) {
  983. var myData = Restangular.stripRestangular(response);
  984. var status = myData.status;
  985. if (status == "500") {
  986. $scope.solutionBBS = [];
  987. } else if (status == "200" && myData.list) {
  988. var data = myData.data[0];
  989. var count = myData.data[1];
  990. $scope.pages = parseInt(count / 7) + 1;
  991. if (page == 0) {
  992. $scope.currentPage = page + 1;
  993. } else {
  994. $scope.currentPage = page;
  995. }
  996. if (data.length > 0) {
  997. $scope.solutionBBS = [];
  998. for (var i = 0; i < data.length; i++) {
  999. data[i].creationTime = getLocalTime(data[i].creationtime);
  1000. data[i].releasetime = getLocalTime(data[i].releasetime);
  1001. if (data[i].solutionReviewDTO.reviewTime == null) {
  1002. data[i].solutionReviewDTO.reviewTime = "暂无回复";
  1003. } else {
  1004. data[i].solutionReviewDTO.reviewTime = getLocalTime(data[i].solutionReviewDTO.reviewTime);
  1005. }
  1006. if (data[i].solutionReviewDTO.userName == null) {
  1007. data[i].solutionReviewDTO.userName = "暂无回复人";
  1008. }
  1009. if (i == 0) {
  1010. data[i].index = 1;
  1011. } else if (i == 1) {
  1012. data[i].index = 2;
  1013. } else if (i == 2) {
  1014. data[i].index = 3;
  1015. } else {
  1016. data[i].index = 4;
  1017. }
  1018. $scope.solutionBBS.push(data[i]);
  1019. }
  1020. }
  1021. }
  1022. });
  1023. } else if (searchKey != "" && searchKey.length > 1) {
  1024. if (angular.isDefined(page)) {
  1025. if (page == 0) {
  1026. page = 1;
  1027. } else if (page == $scope.pages + 1) {
  1028. page = $scope.pages;
  1029. }
  1030. tempPage = page - 1;
  1031. } else {
  1032. tempPage = page = 0;
  1033. $scope.solutionBBS = [];
  1034. }
  1035. // if(page==0){
  1036. // page=1;
  1037. // }else if(page==$scope.pages+1){
  1038. // page=$scope.pages;
  1039. // }
  1040. api_solution.queryBBSSolutions(tempPage, 7, 'createtime', loginUser.id, searchKey).then(function(response) {
  1041. var myData = Restangular.stripRestangular(response);
  1042. var status = myData.status;
  1043. if (status == "500") {
  1044. $scope.solutionBBS = [];
  1045. } else if (status == "200" && myData.list) {
  1046. var data = myData.list;
  1047. var count = myData.totalNum;
  1048. $scope.pages = parseInt(count / 7) + 1;
  1049. if (page == 0) {
  1050. $scope.currentPage = page + 1;
  1051. } else {
  1052. $scope.currentPage = page;
  1053. }
  1054. if (data.length > 0) {
  1055. $scope.solutionBBS = [];
  1056. for (var i = 0; i < data.length; i++) {
  1057. data[i].creationTime = getLocalTime(data[i].createtime);
  1058. data[i].releasetime = getLocalTime(data[i].releasetime);
  1059. if (data[i].solutionReviewDTO.reviewTime == null) {
  1060. data[i].solutionReviewDTO.reviewTime = "暂无回复";
  1061. } else {
  1062. data[i].solutionReviewDTO.reviewTime = getLocalTime(data[i].solutionReviewDTO.reviewTime);
  1063. }
  1064. if (data[i].solutionReviewDTO.userName == null) {
  1065. data[i].solutionReviewDTO.userName = "暂无回复人";
  1066. }
  1067. if (i == 0) {
  1068. data[i].index = 1;
  1069. } else if (i == 1) {
  1070. data[i].index = 2;
  1071. } else if (i == 2) {
  1072. data[i].index = 3;
  1073. } else {
  1074. data[i].index = 4;
  1075. }
  1076. $scope.solutionBBS.push(data[i]);
  1077. }
  1078. }
  1079. }
  1080. });
  1081. }
  1082. }
  1083. //BBS列表切换
  1084. $scope.changeShowList = function(val) {
  1085. $scope.showlist = !$scope.showlist;
  1086. }
  1087. $scope.solutionBBS = [];
  1088. $scope.hotRankings = [];
  1089. $scope.scoreRankings = [];
  1090. $scope.solutionScores = [];
  1091. $scope.currentPage = 1;
  1092. $scope.pages = 0;
  1093. api_solution.fetchBBSSolutions(0, 7, "createtime", loginUser.id).then(function(response) {
  1094. if (response.status == 200 && response.list) {
  1095. $scope.solutionBBS = [];
  1096. var myData = Restangular.stripRestangular(response);
  1097. var data = myData.list;
  1098. var count = myData.totalNum;
  1099. if (count <= 7) {
  1100. $scope.pages = 1;
  1101. }
  1102. for (var i = 0; i < data.length; i++) {
  1103. data[i].creationTime = getLocalTime(data[i].createtime);
  1104. data[i].releasetime = getLocalTime(data[i].releasetime);
  1105. if (data[i].solutionReviewDTO.reviewTime == null) {
  1106. data[i].solutionReviewDTO.reviewTime = "暂无回复";
  1107. } else {
  1108. data[i].solutionReviewDTO.reviewTime = getLocalTime(data[i].solutionReviewDTO.reviewTime);
  1109. }
  1110. if (data[i].solutionReviewDTO.userName == null) {
  1111. data[i].solutionReviewDTO.userName = "暂无回复人";
  1112. }
  1113. if (i == 0) {
  1114. data[i].index = 1;
  1115. } else if (i == 1) {
  1116. data[i].index = 2;
  1117. } else if (i == 2) {
  1118. data[i].index = 3;
  1119. } else {
  1120. data[i].index = 4;
  1121. }
  1122. $scope.solutionBBS.push(data[i]);
  1123. }
  1124. console.log($scope.solutionBBS)
  1125. }
  1126. });
  1127. $scope.fetchByPage = function(page) {
  1128. api_solution.fetchBBSSolutions(0, 7, "createtime", loginUser.id).then(function(response) {
  1129. var sumdata = Restangular.stripRestangular(response);
  1130. var sum = sumdata.list;
  1131. if (angular.isDefined($scope.searchInput) && $scope.searchInput != "" && $scope.searchInput.length > 1) {
  1132. $scope.searchSolution($scope.searchInput, page);
  1133. } else {
  1134. if (page == 0) {
  1135. page = 1;
  1136. } else if (page == $scope.pages + 1) {
  1137. page = $scope.pages;
  1138. } else if (sum / 7 == 1) {
  1139. $scope.pages = 1;
  1140. page = 1;
  1141. }
  1142. api_solution.fetchBBSSolutions(page - 1, 7, "createtime", loginUser.id).then(function(response) {
  1143. if (response.status == 200 && response.list) {
  1144. $scope.solutionBBS = [];
  1145. var myData = Restangular.stripRestangular(response);
  1146. var data = myData.list;
  1147. var count = myData.totalNum;
  1148. if (count / 7 == parseInt(count / 7)) {
  1149. // if(count/7==1){
  1150. // page=1;
  1151. // $scope.pages=parseInt(count/7);
  1152. // }else{
  1153. $scope.pages = parseInt(count / 7);
  1154. // }
  1155. } else {
  1156. $scope.pages = parseInt(count / 7) + 1;
  1157. }
  1158. $scope.currentPage = page;
  1159. for (var i = 0; i < data.length; i++) {
  1160. data[i].creationTime = getLocalTime(data[i].createtime);
  1161. data[i].releasetime = getLocalTime(data[i].releasetime);
  1162. if (data[i].solutionReviewDTO.reviewTime == null) {
  1163. data[i].solutionReviewDTO.reviewTime = "暂无回复";
  1164. } else {
  1165. data[i].solutionReviewDTO.reviewTime = getLocalTime(data[i].solutionReviewDTO.reviewTime);
  1166. }
  1167. if (data[i].solutionReviewDTO.userName == null) {
  1168. data[i].solutionReviewDTO.userName = "暂无回复人";
  1169. }
  1170. if (i == 0) {
  1171. data[i].index = 1;
  1172. } else if (i == 1) {
  1173. data[i].index = 2;
  1174. } else if (i == 2) {
  1175. data[i].index = 3;
  1176. } else {
  1177. data[i].index = 4;
  1178. }
  1179. $scope.solutionBBS.push(data[i]);
  1180. }
  1181. }
  1182. });
  1183. }
  1184. })
  1185. }
  1186. var getLocalTime = function(time) {
  1187. return moment(time).format('YYYY-MM-DD HH:mm:ss');
  1188. // console("time="+time)
  1189. }
  1190. $scope.commentshowSolution = function(solution) {
  1191. var modalInstance = $modal.open({
  1192. templateUrl: 'assets/views/knowledge/tpl/commentknowledge.html',
  1193. controller: function($scope, $http, $modalInstance, APIService, uploader, currentUser, Alert, MomentFormat) {
  1194. var loadData = function() {
  1195. $scope.visions = [];
  1196. $scope.entity = {};
  1197. $scope.showCommentScore = true;
  1198. $scope.comments = [];
  1199. APIService.findSolutionReviewById(loginUser.id, solution.id, 0, 1000).then(function(response) {
  1200. if (response.status != "500") {
  1201. var data = response.list;
  1202. if (angular.isDefined(response.result)) { $scope.showCommentScore = false; }
  1203. for (var i = 0; i < data.length; i++) {
  1204. var object = {};
  1205. object.id = data[i].id;
  1206. object.name = data[i].userName;
  1207. if (data[i].reviewScore > 0) {
  1208. object.score = data[i].reviewScore;
  1209. }
  1210. // object.content=data[i].review;
  1211. var ss = data[i].review;
  1212. var s1 = "";
  1213. if (ss != null) {
  1214. var index = ss.indexOf("<p>");
  1215. var indexs = ss.indexOf("</p>");
  1216. s1 = ss.substring(index + 3, indexs);
  1217. }
  1218. object.content = s1;
  1219. // object.score=data[i].reviewScore;
  1220. object.time = moment(data[i].reviewTime).format('YYYY-MM-DD HH:mm:ss');
  1221. // console.log('object.time='+JSON.stringify(object));
  1222. $scope.comments.push(object);
  1223. }
  1224. }
  1225. });
  1226. APIService.findSolutionById(solution.id).then(function(response) {
  1227. var datas = response.data;
  1228. $scope.entity = {
  1229. "id": datas.id,
  1230. "title": datas.title,
  1231. "keys": datas.keywords,
  1232. "type": datas.typeId,
  1233. "range": datas.solutionRange,
  1234. "number": datas.solutionNumber,
  1235. "content": datas.content,
  1236. "createrUserId": datas.createUserId,
  1237. "createTime": datas.createtime,
  1238. "status": datas.status,
  1239. "hits": datas.hits,
  1240. "relateId": datas.relateId,
  1241. "vision": datas.vision,
  1242. "vision2": "V" + datas.vision,
  1243. // "fileContent":datas.fileContent,
  1244. "replies": datas.replies,
  1245. "scores": datas.scores,
  1246. "hits": datas.hits,
  1247. "fileName": datas.fileName,
  1248. "typeName": datas.typeDTO.typeName
  1249. };
  1250. console.log(datas)
  1251. console.log($scope.entity);
  1252. });
  1253. }
  1254. loadData();
  1255. $scope.options = {
  1256. language: 'zh-cn',
  1257. allowedContent: true,
  1258. entities: false
  1259. };
  1260. $scope.uploader = uploader;
  1261. $scope.getdown = function(filename) {
  1262. $http({
  1263. url: APIService.getSolutionDowpath(solution.id).getRequestedUrl(),
  1264. method: 'GET',
  1265. headers: {
  1266. //'Content-type' : 'application/xls',
  1267. 'Accept': '*/*'
  1268. },
  1269. responseType: 'arraybuffer'
  1270. }).success(function(data, status, headers, config) {
  1271. var file = new Blob([data], {
  1272. type: 'application/octet-stream'
  1273. });
  1274. //trick to download store a file having its URL
  1275. var fileURL = URL.createObjectURL(file);
  1276. var a = document.createElement('a');
  1277. a.href = fileURL;
  1278. a.target = '_blank';
  1279. a.download = filename;
  1280. document.body.appendChild(a);
  1281. a.click();
  1282. }).error(function(data, status, headers, config) {
  1283. console.log(data);
  1284. });
  1285. }
  1286. $scope.ranges = [{
  1287. "id": 1,
  1288. "name": "全局"
  1289. }, {
  1290. "id": 3,
  1291. "name": "组"
  1292. }];
  1293. // $scope.ok = function() {
  1294. // $modalInstance.close($scope.entity);
  1295. // };
  1296. $scope.cancel = function() {
  1297. // api_solution.findSolutions($scope.entity.id).then(function(response){
  1298. // var data6=response.data[0];
  1299. // for(var j=0;j<=$scope.solutionBBS.length;j++){
  1300. // if($scope.solutionBBS.length>0&&$scope.solutionBBS[j].id==$scope.entity.id){
  1301. // $scope.solutionBBS[j].replies=data6.replies;
  1302. // $scope.solutionBBS[j].hits=data6.hits;
  1303. // $scope.solutionBBS[j].scores=data6.scores;
  1304. // break;
  1305. // }
  1306. // }
  1307. // });
  1308. $modalInstance.close($scope.entity.id);
  1309. };
  1310. $scope.saveComment = function(reviewcontent, score) {
  1311. $scope.entity['reviewcontent'] = reviewcontent;
  1312. $scope.entity['score'] = score;
  1313. $modalInstance.close($scope.entity);
  1314. }
  1315. },
  1316. size: 'lg',
  1317. resolve: {
  1318. APIService: function() {
  1319. return api_solution;
  1320. },
  1321. uploader: function() {
  1322. return $scope.uploader;
  1323. },
  1324. currentUser: function() {
  1325. return loginUser.id;
  1326. },
  1327. Alert: function() {
  1328. return SweetAlert;
  1329. },
  1330. MomentFormat: function() {
  1331. return moment;
  1332. }
  1333. }
  1334. });
  1335. modalInstance.result.then(function(selectedItem) {
  1336. if (selectedItem.title) {
  1337. var solutionId = selectedItem.id;
  1338. var reviewContent = selectedItem.reviewcontent;
  1339. // if(solutionId==null){
  1340. var reviewScore;
  1341. if (selectedItem.score) { reviewScore = selectedItem.score.toFixed(1) }
  1342. var data = {
  1343. id: null,
  1344. solutionId: solutionId,
  1345. userId: loginUser.id,
  1346. review: reviewContent,
  1347. reviewScore: reviewScore,
  1348. reviewTime: new Date()
  1349. };
  1350. api_solution.addSolutionReview(data).then(function(response) {
  1351. var status = response.status;
  1352. console.log(response)
  1353. console.log('$scope.apClient=' + JSON.stringify(status));
  1354. if (status == "200") {
  1355. SweetAlert.swal({
  1356. title: "评论知识库!",
  1357. text: "评论知识库成功!",
  1358. type: "success"
  1359. }, function() {
  1360. api_solution.findSolutions(selectedItem.id).then(function(response) {
  1361. var data6 = response.data[0];
  1362. for (var j = 0; j <= $scope.solutionBBS.length; j++) {
  1363. if ($scope.solutionBBS.length > 0 && $scope.solutionBBS[j].id == selectedItem.id) {
  1364. $scope.solutionBBS[j].replies = data6.replies;
  1365. $scope.solutionBBS[j].hits = data6.hits;
  1366. $scope.solutionBBS[j].scores = data6.scores;
  1367. break;
  1368. }
  1369. }
  1370. });
  1371. });
  1372. } else {
  1373. SweetAlert.swal({
  1374. title: "评论知识库!",
  1375. text: "评论知识库失败!",
  1376. type: "error"
  1377. });
  1378. }
  1379. });
  1380. }
  1381. });
  1382. }
  1383. $('#attach-check').on('change', function() {
  1384. $('#attach').toggleClass('hidden');
  1385. });
  1386. $('#attachcheck1').on('change', function() {
  1387. $('#attachdiv1').toggleClass('hidden');
  1388. });
  1389. $('#attachcheck2').on('change', function() {
  1390. $('#attachdiv2').toggleClass('hidden');
  1391. });
  1392. }]);
  1393. app.filter('index', function() {
  1394. return function(array) {
  1395. return (array || []).map(function(item, index) {
  1396. item.order = index + 1;
  1397. return item;
  1398. });
  1399. };
  1400. });
  1401. app.controller('GridOperatorCtrl', ['$http', '$scope', function($http, $scope, $event) {
  1402. if ($scope.item.actions != "" && $scope.item.actions != null) { //1:查看,2:操作(改);3:审核;4.过期;发布更新
  1403. if ($scope.item.actions.indexOf("1") >= 0) { //查看权限
  1404. $scope.item.detailPower = true;
  1405. } else {
  1406. $scope.item.detailPower = false;
  1407. }
  1408. if ($scope.item.status == 4) {
  1409. $scope.item.commentPower = true;
  1410. } else {
  1411. $scope.item.commentPower = false;
  1412. }
  1413. if ($scope.item.actions.indexOf("2") >= 0) { //操作(改)
  1414. if ($scope.item.status == 1 || $scope.item.status == 5 || $scope.item.status == 3) {
  1415. $scope.item.updatePower = true;
  1416. }
  1417. } else {
  1418. $scope.item.updatePower = false;
  1419. }
  1420. if ($scope.item.actions.indexOf("3") >= 0) { //审核
  1421. if ($scope.item.status == 1) {
  1422. $scope.item.reviewPower = true;
  1423. }
  1424. } else {
  1425. $scope.item.reviewPower = false;
  1426. }
  1427. if ($scope.item.actions.indexOf("4") >= 0) { //过期与发布
  1428. if ($scope.item.status == 2) {
  1429. $scope.item.updatePower = true;
  1430. $scope.item.outTimePower = true;
  1431. }
  1432. } else {
  1433. $scope.item.outTimePower = false;
  1434. }
  1435. }
  1436. if ($scope.item.status == 3) { //已发布的才能评论
  1437. $scope.item.publishnotPower = true;
  1438. $scope.item.commontPower = true;
  1439. } else {
  1440. $scope.item.commontPower = false;
  1441. $scope.item.publishnotPower = false;
  1442. }
  1443. // console.log($scope.item.status + " " + $scope.item.commontPower);
  1444. $scope.edit = function() {
  1445. $scope.colobject.grid.appScope.editSolution($scope.item.id);
  1446. // console.log($scope.colobject);
  1447. //$scope.doEdit($scope.item.id);
  1448. }
  1449. $scope.comment = function() {
  1450. $scope.colobject.grid.appScope.commentSolution($scope.item.id);
  1451. //$scope.doComment($scope.item.id);
  1452. }
  1453. $scope.approval = function() {
  1454. $scope.colobject.grid.appScope.approvalSolution($scope.item.id, $scope.item.outTimePower);
  1455. //$scope.doApproval($scope.item.id,$scope.item.outTimePower);
  1456. }
  1457. $scope.publish = function() {
  1458. $scope.colobject.grid.appScope.approvalSolution($scope.item.id, $scope.item.outTimePower);
  1459. //$scope.doApproval($scope.item.id,$scope.item.outTimePower);
  1460. }
  1461. $scope.publishnot = function() {
  1462. $scope.colobject.grid.appScope.approvalSolution($scope.item.id, $scope.item.outTimePower);
  1463. //$scope.doApproval($scope.item.id,$scope.item.outTimePower);
  1464. }
  1465. $scope.detail = function() {
  1466. $scope.colobject.grid.appScope.detailSolution($scope.item.id);
  1467. // console.log($scope.colobject);
  1468. }
  1469. }]);
  1470. app.directive('gridoperator', function() {
  1471. return {
  1472. restrict: 'E',
  1473. scope: {
  1474. item: '=',
  1475. colobject: '='
  1476. // doEdit: '&',
  1477. // doComment: '&',
  1478. // doApproval: '&'
  1479. },
  1480. controller: 'GridOperatorCtrl',
  1481. template: '<div class="links cl-effect-1">' +
  1482. '<a ng-click="detail()" ng-show="{{item.detailPower}}" tooltip="查看" tooltip-placement="left"><i class="ti-eye"></i></a>' +
  1483. '<a ng-click="edit()" ng-show="{{item.updatePower}}" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil"></i></a>' +
  1484. '<a ng-click="comment()" ng-show="{{item.commontPower}}" tooltip="评论" tooltip-placement="left"><i class="fa fa-send"></i></a>' +
  1485. '<a ng-click="approval()" ng-show="{{item.reviewPower}}" tooltip="审核" tooltip-placement="left"><i class="fa fa-ellipsis-v"></i></a>' +
  1486. '<a ng-click="publish()" ng-show="{{item.outTimePower}}" tooltip="发布" tooltip-placement="left"><i class="ti-clipboard"></i></a>' +
  1487. '<a ng-click="publishnot()" ng-show="{{item.publishnotPower}}" tooltip="撤销" tooltip-placement="left"><i class=" ti-brush-alt"></i></a>' +
  1488. '</div>'
  1489. };
  1490. });