All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template-application-launchpad.api.launchpad.tiles.js.template Maven / Gradle / Ivy

/*
 * Copyright (c) 2017 SAP and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * SAP - initial API and implementation
 */

var extensions = require('core/v3/extensions');
var request = require('http/v3/request');
var response = require('http/v3/response');

var tiles = [];

var relativePath = getRelativePath(request.getParameter('pathSegments'));
var tileExtensions = extensions.getExtensions('launchpad-{{extensionName}}-tiles');
for (var i = 0; tileExtensions !== null && i < tileExtensions.length; i++) {
    var tileExtension = require(tileExtensions[i]);
    var tile = tileExtension.getTile(relativePath);
    var found = false;
    for (var j = 0 ; j < tiles.length ; j ++) {
    	if (tiles[j].group === tile.group) {
    		tiles[j].tiles.push(tile);
    		found = true;
    	}
    }
    if (!found) {
    	tiles.push({
    		'group': tile.group,
    		'tiles': [tile]
    	});
    }
}

tiles = tiles.sort(function(a, b) {
	var result = a.tiles[0].order - b.tiles[0].order;
	if (result === 0) {
		return a.group < b.group ? -1 : a.group > b.group ? 1 : 0;
	}
	return result;
});

response.println(JSON.stringify(tiles));

function getRelativePath(pathSegments) {
	var relativePath = '';
	for (var i = 0; i < pathSegments; i ++) {
		relativePath += '../';
	}
	return relativePath;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy