'use strict';

var  ensureDb = require('dbjs/valid-dbjs')
  , memoize = require('memoizee');

module.exports = memoize(function (db) {
	// ensure db
	ensureDb(db);

	var catalogs = [];
	// all enums
	var enums = db.StringLine.extensions.toArray().filter(function (extension) {
		return extension.meta && extension.members;
	}).map(function (extension) {
		var catalogItem = { name: extension.__id__ };
		catalogItem.options = extension.members.toArray().map(function (option) {
			return { name: option, label: extension.meta[option].label };
		});
		return catalogItem;
	});
	[].push.apply(catalogs, enums);

	// services
	var services = db.BusinessProcess.extensions.toArray().map(function (bp) {
		return { name: bp.__id__, label: bp.prototype.label };
	});
	catalogs.push({ services: services });

	// documents
	var documents = db.Document.extensions.toArray().map(function (doc) {
		return { name: doc.__id__, label: doc.prototype.label };
	});
	catalogs.push({ documents: documents });

	// institutions
	var institutions = db.Institution.instances.toArray().map(function (institution) {
		return { name: institution.__id__, label: institution.name };
	});
	catalogs.push({ institutions: institutions });

	return catalogs;

}, { length: 0 });

@@ -574,225 +574,726 @@
 );%0A%09
-%5B%5D.push.apply(catalogs, enums);%0A%0A%09// services%0A%09var services = db.BusinessProcess.extensions.toArray().map(function (bp) %7B%0A%09%09return %7B name: bp.__id__, label: bp.prototype.label %7D;%0A%09%7D);%0A%09catalogs.push(%7B services: servic
+catalogs.push(%7B enums: enums %7D);%0A%0A%09// services + its roles%0A%09var roles = %5B%5D;%0A%09var bpRoles =%7B%7D;%0A%0A%09var services = db.BusinessProcess.extensions.toArray().map(function (bp) %7B%0A%09%09bp.prototype.processingSteps.map.forEach(function (step)%7B%0A%09%09%09// if group - check the substeps%0A%09%09%09if (step.steps) %7B%0A%09%09%09%09%09step.steps.map.forEach(function (subStep) %7B%0A%09%09%09%09%09%09bpRoles%5BsubStep.key%5D = %7B name: subStep.key, label: subStep.label %7D;%0A%09%09%09%09%09%7D);%0A%09%09%09%7D else %7B%0A%09%09%09%09bpRoles%5Bstep.key%5D = %7B name: step.key, label: step.label %7D;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%0A%09%09return %7B name: bp.__id__, label: bp.prototype.label %7D;%0A%09%7D);%0A%09roles = Object.keys(bpRoles).map(function (key) %7B%0A%09%09%09return bpRoles%5Bkey%5D;%0A%09%7D);%0A%0A%09catalogs.push(%7B services: services %7D);%0A%09catalogs.push(%7B roles: rol
 es %7D

Add the processing steps