123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2016, 2017
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'doT', 'q', 'bi/glass/app/util/View', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/datasource/App', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/i18n/Formatter'], function ($, dot, Q, View, _, StringResource, App, PropertyUIControl, Formatter) {
- //NOSONAR: needed for amd
- 'use strict'; //NOSONAR: meant to be strict
- var MAX_ROWS = 10000;
- var DEFAULT_ROWS = 1000;
- var LoadOptionsView = View.extend({
- _formatedMaxRows: null,
- _state: {
- 'dataStatistics': 'all',
- 'dataSamplingSize': DEFAULT_ROWS,
- 'advancedOpen': false,
- 'importPrimaryForeignKeys': true
- },
- /**
- * @constructor
- */
- init: function init(options) {
- LoadOptionsView.inherited('init', this, arguments);
- _.extend(this, options);
- this._formatedMaxRows = Formatter.format(MAX_ROWS, {
- type: 'number',
- locale: this.glassContext.services.userProfile.preferences.contentLocale
- });
- this.updateState(this.prop, null, true);
- },
- updateState: function updateState(key, value, withoutRedraw) {
- var obj = {};
- if ($.type(key) !== 'string') {
- obj = key;
- } else {
- obj[key] = value;
- }
- $.extend(this._state, obj);
- this._updateComputedState(); //update parent states after local ones are in sync
- this.parentView.updateState(this._state, null, withoutRedraw);
- if (!withoutRedraw) {
- this._redraw();
- }
- },
- _updateComputedState: function _updateComputedState() {
- this._state.dataSamplingChecked = this._getDataSamplingState();
- this._state.dataStatisticsChecked = this._getDataStatisticsState();
- },
- _getDataSamplingState: function _getDataSamplingState() {
- if (this._state.dataSamplingSize > 0) {
- return true;
- }
- return false;
- },
- _getDataStatisticsState: function _getDataStatisticsState() {
- if (this._state.dataStatistics === 'all') {
- return true;
- }
- return false;
- },
- _redraw: function _redraw() {
- this.$el.empty();
- return this.render();
- },
- /**
- Main entry point - will render the load option view
- **/
- render: function render() {
- var deferred = Q.defer();
- var items = [{
- 'type': 'HintText',
- 'label': StringResource.get('modelAssistHint'),
- 'id': 'modelAssistHint'
- }, {
- 'type': 'CheckBox',
- 'label': StringResource.get('IncludePFKey'),
- 'name': 'importPrimaryForeignKeys',
- 'checked': this._state.importPrimaryForeignKeys,
- 'onChange': this.updateState.bind(this)
- }, {
- 'type': 'CheckBox',
- 'label': StringResource.get('dataSampling'),
- 'name': 'dataSamplingChecked',
- 'checked': this._state.dataSamplingChecked,
- 'onChange': this.dataSamplingOnChange.bind(this)
- }, {
- 'id': 'admin_load_options_max_rows',
- 'type': 'SingleLineValue',
- 'label': StringResource.get('maxRows', {
- 'maxRows': this._formatedMaxRows
- }),
- 'name': 'dataSamplingSize',
- 'editable': this._state.dataSamplingChecked === true,
- 'onChange': this._maxRowsOnChange.bind(this),
- 'value': this._state.dataSamplingChecked === true ? this._state.dataSamplingSize : '',
- 'disabled': !(this._state.dataSamplingChecked === true)
- }];
- this._propertyUIControl = new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el,
- 'items': items
- });
- this._propertyUIControl.render().then(function () {
- deferred.resolve();
- });
- return deferred.promise;
- },
- _dataStatisticsOnChange: function _dataStatisticsOnChange(key, value) {
- this.updateState(key, value ? 'all' : 'none');
- },
- dataSamplingOnChange: function dataSamplingOnChange(key, value) {
- this.updateState({
- 'dataSamplingSize': value ? DEFAULT_ROWS : -1
- });
- },
- _maxRowsOnChange: function _maxRowsOnChange(key, value) {
- var val = value;
- if (!$.isNumeric(value)) {
- val = DEFAULT_ROWS;
- } else if (value > MAX_ROWS) {
- val = MAX_ROWS;
- } else if (value < 1) {
- val = 1;
- }
- this.updateState(key, val);
- }
- });
- return LoadOptionsView;
- });
|