79 lines
3.7 KiB
JavaScript
79 lines
3.7 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('knowledgeArticleModule')
|
|
.controller('KnowledgeArticleAssessmentController', ['$scope', 'userModel', 'knowledgeArticleModel', 'systemAlertService', 'events', '$timeout',
|
|
function ($scope, userModel, knowledgeArticleModel, systemAlertService, events, $timeout) {
|
|
$scope.assessmentQuestionsList = [];
|
|
$scope.dataIsLoading = false;
|
|
$scope.showMetadataPreview = false;
|
|
$scope.metadataQuestion = [];
|
|
$scope.duplicateArticlesList = [];
|
|
$scope.getAssessmentQuestions = function () {
|
|
$scope.dataIsLoading = true;
|
|
if (!$scope.article.author.company) {
|
|
$scope.article.author.company = { name: null };
|
|
}
|
|
return knowledgeArticleModel.getAssessmentQuestions($scope.article.author.company.name, $scope.article.author.organization).then(function (data) {
|
|
$scope.assessmentQuestionsList = data;
|
|
}).catch(function (error) {
|
|
systemAlertService.error({
|
|
text: error.data.error,
|
|
clear: false
|
|
});
|
|
}).finally(function () {
|
|
$scope.dataIsLoading = false;
|
|
});
|
|
};
|
|
$scope.submitAnswers = function () {
|
|
$scope.dataIsLoading = true;
|
|
var answers = [];
|
|
_.each($scope.assessmentQuestionsList, function (question) {
|
|
answers.push(question.getAnswer());
|
|
});
|
|
knowledgeArticleModel.submitAssessment($scope.articleId, answers).then(function (data) {
|
|
$scope.dataIsLoading = false;
|
|
$scope.exitAssessmentMode();
|
|
$timeout(function () {
|
|
systemAlertService.success({ text: data.message, clear: true, hide: 10000 });
|
|
}, 100);
|
|
}).catch(function (error) {
|
|
systemAlertService.error({
|
|
text: error.data.error,
|
|
clear: false
|
|
});
|
|
}).finally(function () {
|
|
$scope.dataIsLoading = false;
|
|
});
|
|
};
|
|
$scope.toggleMetadataView = function (showPreview, metadataQuestion) {
|
|
$scope.showMetadataPreview = showPreview;
|
|
if (!showPreview) {
|
|
$scope.metadataQuestion.length = 0;
|
|
return;
|
|
}
|
|
$scope.metadataQuestion.push(metadataQuestion);
|
|
};
|
|
$scope.handleActionBtnClick = function (type, params) {
|
|
switch (type) {
|
|
case 'CHECK_DUPLICATE':
|
|
$scope.$emit(events.TOGGLE_CHECK_DUPLICATE_MODE, true);
|
|
break;
|
|
case 'CHECK_METADATA':
|
|
$scope.toggleMetadataView(true, params.currentContext);
|
|
break;
|
|
case 'REMOVE_DUPLICATES':
|
|
$scope.$broadcast(events.ASSESSMENT_REMOVE_DUPLICATES);
|
|
break;
|
|
}
|
|
};
|
|
$scope.$on(events.DUPLICATE_ARTICLE_FOUND, function (event, duplicateArticles) {
|
|
var contextQuestion = _.find($scope.assessmentQuestionsList, { 'actionType': 'CHECK_DUPLICATE' });
|
|
$scope.duplicateArticlesList = duplicateArticles;
|
|
contextQuestion.desirableAnswer = !_.isEmpty(duplicateArticles);
|
|
});
|
|
$scope.getAssessmentQuestions();
|
|
}
|
|
]);
|
|
})();
|