123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2016
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'doT', 'underscore', 'bi/admin/common/ui/WidgetView', 'bi/commons/utils/Utils', 'bi/admin/nls/StringResource', 'text!bi/admin/common/ui/testflow/templates/TestFlowTemplate.html'], function ($, dot, _, WidgetView, Utils, StringResource, template) {
- 'use strict'; //NOSONAR: meant to be strict
- var TestFlowStates = {
- 'INIT': 'init',
- 'TESTING': 'testing',
- 'CANCELED': 'canceled',
- 'FAILED': 'failed',
- 'SUCCESS': 'success'
- };
- var TestFlow = WidgetView.extend({
- widgetName: 'testflow',
- state: TestFlowStates.INIT,
- times: 0,
- init: function init(options) {
- TestFlow.inherited('init', this, arguments);
- var query = '[data-bi-testflow]';
- if (this.element.is(query)) {
- this._create();
- this._initEvents();
- this._updateUIState(true);
- }
- },
- _create: function _create() {
- var tempInfo = {
- strings: {
- test: StringResource.get('test'),
- testing: StringResource.get('testing'),
- cancel: StringResource.get('cancel'),
- canceled: StringResource.get('canceled'),
- failed: StringResource.get('testingFailed'),
- success: StringResource.get('success'),
- retry: StringResource.get('retry')
- }
- };
- var sHtml = dot.template(template)(tempInfo);
- this.$el.append(sHtml);
- var $workingIndicator = $(Utils.getLoadingAnimation(1));
- $workingIndicator.addClass('loginWorking');
- this.$el.find('#indicator').append($workingIndicator[0]);
- },
- _updateTimes: function _updateTimes() {
- if (this.state === TestFlowStates.TESTING) {
- this.$el.find('#times').text("(" + this.times++ + ")");
- window.setTimeout(function () {
- this._updateTimes();
- }.bind(this), 1000);
- } else {
- this.times = 0;
- }
- },
- _initEvents: function _initEvents() {
- this.$el.find('#test').on('primaryaction', function () {
- this.trigger('startTest');
- }.bind(this));
- this.$el.find('#cancel').on('primaryaction', function () {
- this.trigger('cancel');
- }.bind(this));
- this.$el.find('#retry').on('primaryaction', function () {
- this.trigger('startTest');
- }.bind(this));
- this.$el.find('#more').on('primaryaction', function (e) {
- this._toggleDetail($(e.target));
- }.bind(this));
- },
- _toggleDetail: function _toggleDetail() {
- var hasShow = this.$el.hasClass('showdetail');
- var hasHide = this.$el.hasClass('hidedetail');
- if (!hasShow && !hasHide) {
- this.$el.addClass('showdetail');
- } else {
- if (hasShow) {
- this.$el.removeClass('showdetail');
- this.$el.addClass('hidedetail');
- } else {
- if (hasHide) {
- this.$el.removeClass('hidedetail');
- this.$el.addClass('showdetail');
- }
- }
- }
- },
- _renderMessages: function _renderMessages(messages) {
- var $primText = this.$el.find('#primaryText');
- $primText.text('');
- var $detail = this.$el.find('#detail');
- $detail.empty();
- this.$el.addClass('nodetail');
- if (_.isArray(messages) && !_.isEmpty(messages)) {
- var pt = _.first(messages) || StringResource.get('unknown');
- $primText.text(pt);
- var detail = _.rest(messages, 1);
- var sHtml = "";
- _.each(detail, function (msg) {
- sHtml = sHtml + "<div class='msg'>" + _.escape(msg) + "</div>";
- });
- $detail.append(sHtml);
- if (sHtml) {
- this.$el.removeClass('nodetail');
- }
- } else {
- $primText.text(StringResource.get('unknown'));
- }
- },
- start: function start() {
- this.state = TestFlowStates.TESTING;
- this._updateUIState(true);
- this._updateTimes();
- },
- cancel: function cancel() {
- this.state = TestFlowStates.CANCELED;
- this._updateUIState(true);
- },
- failed: function failed(messages) {
- this._renderMessages(messages);
- this.state = TestFlowStates.FAILED;
- this._updateUIState(false);
- },
- success: function success(messages) {
- this._renderMessages(messages);
- this.state = TestFlowStates.SUCCESS;
- this._updateUIState(true);
- },
- _updateUIState: function _updateUIState(hideDetail) {
- if (hideDetail) {
- this.$el.removeClass('showdetail hidedetail');
- }
- this.$el.find('td').hide();
- switch (this.state) {
- case TestFlowStates.INIT:
- this.$el.find('.bi-admin-testflow-test').show();
- break;
- case TestFlowStates.TESTING:
- this.$el.find('.bi-admin-testflow-testing').show();
- this.$el.find('.bi-admin-testflow-cancel').show();
- break;
- case TestFlowStates.CANCELED:
- this.$el.find('.bi-admin-testflow-canceled').show();
- this.$el.find('.bi-admin-testflow-retry').show();
- break;
- case TestFlowStates.FAILED:
- this.$el.find('.bi-admin-testflow-failed').show();
- this.$el.find('.bi-admin-testflow-retry').show();
- break;
- case TestFlowStates.SUCCESS:
- this.$el.find('.bi-admin-testflow-success').show();
- this.$el.find('.bi-admin-testflow-success #more').hide();
- this.$el.find('.bi-admin-testflow-test').show();
- break;
- }
- }
- });
- return TestFlow;
- });
|