/**
	 * Check report name obtained from the 'rn' parameter and load default dashboard if rn parameter doesn't
	 * contain valid dashboard name.
	 * @param {object} location Location object.
	 * @returns {string} fixed dashboard full name (or empty string if can't find default dashboard).
	 */
	_getWantedReportFullName(location) {
		const urlFullName = location.fullName;
		const categories = this.categories.getValue();
		const isUrlFullNameExist =
			testFullName => categories.some(cat => cat.dashboards.some(dashName => dashName === testFullName));

		// calc current dashboard category
		const currentCategoryName = this._getWantedCategoryName();

		// calc current dashboard full name
		let currentDashboardFullName = '';
		let isCurrentDashbiardNameSet = false;
		if (isUrlFullNameExist(urlFullName)) {
			currentDashboardFullName = urlFullName;
			isCurrentDashbiardNameSet = true;
		}
		if (!isCurrentDashbiardNameSet && this.$izendaDashboardConfig.defaultDashboardName !== null) {
			currentDashboardFullName = this.$izendaDashboardConfig.defaultDashboardName;
			if (currentDashboardFullName && currentCategoryName && !this.$izendaUtilService.isUncategorized(currentCategoryName)) {
				currentDashboardFullName =
					currentCategoryName + this.$izendaSettingsService.getCategoryCharacter() + currentDashboardFullName;
			}
			isCurrentDashbiardNameSet = true;
		}

		// couldn't find dashboard - use first
		if (!isCurrentDashbiardNameSet) {
			const defaultCats = categories.filter(cat => cat.dashboards.length);
			currentDashboardFullName = defaultCats.length ? defaultCats[0].dashboards[0] : '';
		}

		return currentDashboardFullName;
	}
Example #2
0
	getReportFullName(reportName: string, reportCategory?: string): string {
		let result = null;
		if (reportName) {
			result = '';
			if (!this.$izendaUtilService.isUncategorized(reportCategory))
				result = reportCategory + this.getCategoryCharacter();
			result += reportName;
		}
		return result;
	}
		return this.$q((resolve, reject) => {
			try {

				// prepare report name variables
				let newReportName = reportName || null;
				let newReportCategory = categoryName || null;
				let newReportFullName: string;
				if (this.$izendaUtilService.isUncategorized(newReportCategory))
					newReportCategory = null;
				if (newReportName) {
					// if name was set
					newReportFullName = this.$izendaUtilService.createReportFullName(newReportName,
						this.$izendaSettingsService.getCategoryCharacter(),
						newReportCategory);
				} else {
					// if name wasn't set
					const currentLocation = this.location.getValue();
					newReportName = currentLocation.name;
					newReportCategory = currentLocation.category;
					newReportFullName = currentLocation.fullName;
				}

				// update report names in the model
				const model: IzendaDashboardModel = this.model.getValue();
				model.reportCategory = newReportCategory;
				model.reportName = newReportName;
				model.reportFullName = this.$izendaSettingsService.getReportFullName(newReportName, newReportCategory);

				// create json and send save request
				const json = this.createJsonConfigForSend();
				this.$izendaDashboardQueryService.saveDashboardNew(json).then(() => {
					this.$izendaUrlService.setReportFullName(newReportFullName);
					resolve();
				}, (error) => {
					reject(error);
				});
			} catch (e) {
				reject(e);
			}
		});
		const category = categories.first(cat => currentCategoryName === cat.name ||
			(this.$izendaUtilService.isUncategorized(currentCategoryName) && this.$izendaUtilService.isUncategorized(cat.name)));
			const uncategorized = categories.first(cat => this.$izendaUtilService.isUncategorized(cat.name));