ngx-monitorias-uniandes-lib
Version:
This library is used for Monitorias-Uniandes system.
153 lines • 7.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var constants_1 = require("./constants");
var md5_1 = require("ts-md5/dist/md5");
var service_locator_1 = require("../service-locator");
var UtilsService = /** @class */ (function () {
function UtilsService(mainLocator) {
this.mainLocator = mainLocator;
}
UtilsService.prototype.clearUndefinedProperties = function (obj) {
Object.keys(obj).forEach(function (key) { return (obj[key] === undefined || obj[key] === '' || obj[key] === null) && delete obj[key]; });
};
UtilsService.prototype.clearUndefinedValuesInArray = function (list) {
return list = list.map(function (elm) {
if (!elm) {
list.splice(list.indexOf(elm), 1);
}
});
};
UtilsService.prototype.compareUrlWithRegx = function (url, regExp) {
var resultMatch = url.match(regExp);
return resultMatch ? true : false;
};
UtilsService.prototype.isAcademiaPhdStudentsListUrl = function (url) {
return this.compareUrlWithRegx(url, constants_1.PHDSTUDENTLIST_ROUTE);
};
UtilsService.prototype.isAcademiaPhdStudentsDetailUrl = function (url) {
return this.compareUrlWithRegx(url, constants_1.PHDSTUDENTDETAIL_ROUTE);
};
UtilsService.prototype.isAcademiaAllStudentsListUrl = function (url) {
return this.compareUrlWithRegx(url, constants_1.ALLSTUDENTLIST_ROUTE);
};
UtilsService.prototype.isAcademiaAllStudentsDetailUrl = function (url) {
return this.compareUrlWithRegx(url, constants_1.ALLSTUDENTDETAIL_ROUTE);
};
UtilsService.prototype.generateMd5 = function (value) {
var md5 = md5_1.Md5.hashAsciiStr(value);
return md5.toString();
};
UtilsService.prototype.normalizedParamsToHash = function (modelData) {
var query = new Map();
var queryKeys = [];
var sortParamsValues = [];
if (modelData.searchParams) {
this.clearUndefinedProperties(modelData.searchParams);
Object.keys(modelData.searchParams).forEach(function (key) { return query.set(key, modelData.searchParams[key]); });
}
if (modelData.optionalFields) {
this.clearUndefinedProperties(modelData.optionalFields);
Object.keys(modelData.optionalFields).forEach(function (key) { return query.set(key, 'true'); });
}
query.set(constants_1.UR_PARAM, modelData.currentUser.userName);
query.set(constants_1.REPORT_PARAM, modelData.reportName);
query.forEach(function (value, key) {
queryKeys.push(key);
});
queryKeys.sort();
sortParamsValues = this.getSortParamsValues(queryKeys, query);
sortParamsValues.push(modelData.currentDate);
var concatSortParams = sortParamsValues.reduce(function (acum, value) { return acum.toString() + value.toString(); });
return concatSortParams;
};
UtilsService.prototype.setParams = function (modelData, hash) {
var paramsArray = [];
if (modelData) {
paramsArray.push(constants_1.REPORT_PARAM + '=' + modelData.reportName);
if (modelData.currentUser) {
paramsArray.push(constants_1.UR_PARAM + '=' + modelData.currentUser.userName);
}
if (modelData.searchParams) {
Object.keys(modelData.searchParams).forEach(function (key) {
if (key === 'phdStatusArray') {
modelData.searchParams[key].forEach(function (element) {
paramsArray.push(constants_1.PHD_STATUS + '=' + element);
});
}
else {
paramsArray.push(key + '=' + modelData.searchParams[key]);
}
});
}
if (modelData.optionalFields) {
Object.keys(modelData.optionalFields).forEach(function (key) { return paramsArray.push(key + '=' + modelData.optionalFields[key]); });
}
;
if (hash) {
paramsArray.push(constants_1.HASH_PARAM + '=' + hash);
}
paramsArray.push(constants_1.FORMAT_PARAM + '=' + modelData.format);
}
var params = paramsArray.reduce(function (acum, value) { return acum + '&' + value; });
return params;
};
UtilsService.prototype.getDateForUrl = function () {
var today = new Date();
var month, date = "";
var year = today.getFullYear();
(today.getMonth() + 1) < 10 ? month = "0" + (today.getMonth() + 1).toString() : month = (today.getMonth() + 1).toString();
(today.getDate() + 1) < 10 ? date = "0" + (today.getDate()).toString() : date = (today.getDate()).toString();
var arrayToday = year.toString() + month.toString() + date.toString();
return arrayToday;
};
UtilsService.prototype.getSortParamsValues = function (keysSort, query) {
var sortParams = [];
keysSort.forEach(function (element) {
sortParams.unshift(query.get(element));
});
return sortParams;
};
UtilsService.prototype.setIdTypes = function (idsType) {
var re = new RegExp("^(http|https)://", "i");
var newItem;
for (var _i = 0, idsType_1 = idsType; _i < idsType_1.length; _i++) {
var item = idsType_1[_i];
newItem = item.value;
if (!re.test(item.value)) {
switch (item.idType) {
case "LINKEDIN":
newItem = constants_1.LINKEDIN + item.value;
break;
case "FACEBOOK":
newItem = constants_1.FACEBOOK + item.value;
break;
case "TWITTER":
newItem = constants_1.TWITTER + item.value;
break;
case "ORCID":
newItem = constants_1.ORCID + item.value;
break;
case "ACADEMIA_EDU":
newItem = constants_1.ACADEMIA + item.value;
break;
case "RESEARCHGATE":
newItem = constants_1.RESEARCHGATE + item.value;
break;
}
item.value = newItem;
}
}
return idsType;
};
UtilsService.decorators = [
{ type: core_1.Injectable },
];
/** @nocollapse */
UtilsService.ctorParameters = function () { return [
{ type: service_locator_1.ServiceLocator, },
]; };
return UtilsService;
}());
exports.UtilsService = UtilsService;
//# sourceMappingURL=utils.service.js.map