Skip to content

Commit

Permalink
Regenerate with new custom-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nedelcho-delchev-tues committed Apr 8, 2024
1 parent 1f88d16 commit 8507c65
Show file tree
Hide file tree
Showing 42 changed files with 355 additions and 369 deletions.
3 changes: 3 additions & 0 deletions codbex-currencies/codbex-currencies.gen
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"workspaceName": "workspace",
"filePath": "codbex-currencies.model",
"templateId": "template-application-angular/template/template.js",
"dataSource": "DefaultDB",
"perspectives": {
"Currencies": {
"views": [
Expand Down Expand Up @@ -247,6 +248,7 @@
"title": "Currency",
"tooltip": "Currency",
"type": "PRIMARY",
"dataSource": "DefaultDB",
"referencedProjections": [],
"primaryKeys": [
"Id"
Expand Down Expand Up @@ -522,6 +524,7 @@
"title": "CurrencyRate",
"tooltip": "CurrencyRate",
"type": "DEPENDENT",
"dataSource": "DefaultDB",
"referencedProjections": [],
"primaryKeys": [
"Id"
Expand Down
15 changes: 14 additions & 1 deletion codbex-currencies/gen/api/Currencies/CurrencyRateService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Controller, Get, Post, Put, Delete, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { CurrencyRateRepository, CurrencyRateEntityOptions } from "../../dao/Currencies/CurrencyRateRepository";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

const validationModules = await Extensions.loadExtensionModules("codbex-currencies-Currencies-CurrencyRate", ["validate"]);

@Controller
class CurrencyRateService {

Expand Down Expand Up @@ -31,6 +35,7 @@ class CurrencyRateService {
@Post("/")
public create(entity: any) {
try {
this.validateEntity(entity);
entity.Id = this.repository.create(entity);
response.setHeader("Content-Location", "/services/ts/codbex-currencies/gen/api/Currencies/CurrencyRateService.ts/" + entity.Id);
response.setStatus(response.CREATED);
Expand Down Expand Up @@ -73,7 +78,7 @@ class CurrencyRateService {
const id = parseInt(ctx.pathParameters.id);
const entity = this.repository.findById(id);
if (entity) {
return entity
return entity;
} else {
HttpUtils.sendResponseNotFound("CurrencyRate not found");
}
Expand All @@ -86,6 +91,7 @@ class CurrencyRateService {
public update(entity: any, ctx: any) {
try {
entity.Id = ctx.pathParameters.id;
this.validateEntity(entity);
this.repository.update(entity);
return entity;
} catch (error: any) {
Expand Down Expand Up @@ -118,4 +124,11 @@ class CurrencyRateService {
HttpUtils.sendInternalServerError(error.message);
}
}

private validateEntity(entity: any): void {
for (const next of validationModules) {
next.validate(entity);
}
}

}
24 changes: 23 additions & 1 deletion codbex-currencies/gen/api/Currencies/CurrencyService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Controller, Get, Post, Put, Delete, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { CurrencyRepository, CurrencyEntityOptions } from "../../dao/Currencies/CurrencyRepository";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

const validationModules = await Extensions.loadExtensionModules("codbex-currencies-Currencies-Currency", ["validate"]);

@Controller
class CurrencyService {

Expand All @@ -24,6 +28,7 @@ class CurrencyService {
@Post("/")
public create(entity: any) {
try {
this.validateEntity(entity);
entity.Id = this.repository.create(entity);
response.setHeader("Content-Location", "/services/ts/codbex-currencies/gen/api/Currencies/CurrencyService.ts/" + entity.Id);
response.setStatus(response.CREATED);
Expand Down Expand Up @@ -66,7 +71,7 @@ class CurrencyService {
const id = parseInt(ctx.pathParameters.id);
const entity = this.repository.findById(id);
if (entity) {
return entity
return entity;
} else {
HttpUtils.sendResponseNotFound("Currency not found");
}
Expand All @@ -79,6 +84,7 @@ class CurrencyService {
public update(entity: any, ctx: any) {
try {
entity.Id = ctx.pathParameters.id;
this.validateEntity(entity);
this.repository.update(entity);
return entity;
} catch (error: any) {
Expand Down Expand Up @@ -111,4 +117,20 @@ class CurrencyService {
HttpUtils.sendInternalServerError(error.message);
}
}

private validateEntity(entity: any): void {
if (entity.Code?.length > 3) {
throw new ValidationError(`The 'Code' exceeds the maximum length of [3] characters`);
}
if (entity.Name?.length > 127) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [127] characters`);
}
if (entity.Numeric?.length > 3) {
throw new ValidationError(`The 'Numeric' exceeds the maximum length of [3] characters`);
}
for (const next of validationModules) {
next.validate(entity);
}
}

}
8 changes: 8 additions & 0 deletions codbex-currencies/gen/api/utils/ForbiddenError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class ForbiddenError extends Error {
readonly name = "ForbiddenError";
readonly stack = (new Error()).stack;

constructor(message: string = "You don't have permission to access this resource") {
super(message);
}
}
8 changes: 8 additions & 0 deletions codbex-currencies/gen/api/utils/ValidationError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class ValidationError extends Error {
readonly name = "ValidationError";
readonly stack = (new Error()).stack;

constructor(message: string) {
super(message);
}
}
5 changes: 4 additions & 1 deletion codbex-currencies/gen/dao/Currencies/Currency.extensionpoint
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"location":"codbex-currencies/gen/dao/Currencies/Currency.extensionpoint","name":"codbex-currencies/Currencies/Currency","description":"Extension Point for codbex-currencies Currencies Currency"}
{
"name": "codbex-currencies-Currencies-Currency",
"description": "Extension Point for the codbex-currencies-Currencies-Currency entity"
}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"location":"codbex-currencies/gen/dao/Currencies/CurrencyRate.extensionpoint","name":"codbex-currencies/Currencies/CurrencyRate","description":"Extension Point for codbex-currencies Currencies CurrencyRate"}
{
"name": "codbex-currencies-Currencies-CurrencyRate",
"description": "Extension Point for the codbex-currencies-Currencies-CurrencyRate entity"
}
10 changes: 5 additions & 5 deletions codbex-currencies/gen/dao/Currencies/CurrencyRateRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class CurrencyRateRepository {

private readonly dao;

constructor(dataSource?: string) {
constructor(dataSource = "DefaultDB") {
this.dao = daoApi.create(CurrencyRateRepository.DEFINITION, null, dataSource);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ export class CurrencyRateRepository {
return this.dao.count(options);
}

public customDataCount(options?: CurrencyRateEntityOptions): number {
public customDataCount(): number {
const resultSet = query.execute('SELECT COUNT(*) AS COUNT FROM "CODBEX_CURRENCYRATE"');
if (resultSet !== null && resultSet[0] !== null) {
if (resultSet[0].COUNT !== undefined && resultSet[0].COUNT !== null) {
Expand All @@ -197,14 +197,14 @@ export class CurrencyRateRepository {
}

private async triggerEvent(data: CurrencyRateEntityEvent) {
const triggerExtensions = await extensions.loadExtensionModules("codbex-currencies/Currencies/CurrencyRate", ["trigger"]);
const triggerExtensions = await extensions.loadExtensionModules("codbex-currencies-Currencies-CurrencyRate", ["trigger"]);
triggerExtensions.forEach(triggerExtension => {
try {
triggerExtension.trigger(data);
} catch (error) {
console.error(error);
}
});
producer.topic("codbex-currencies/Currencies/CurrencyRate").send(JSON.stringify(data));
producer.topic("codbex-currencies-Currencies-CurrencyRate").send(JSON.stringify(data));
}
}
}
10 changes: 5 additions & 5 deletions codbex-currencies/gen/dao/Currencies/CurrencyRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class CurrencyRepository {

private readonly dao;

constructor(dataSource?: string) {
constructor(dataSource = "DefaultDB") {
this.dao = daoApi.create(CurrencyRepository.DEFINITION, null, dataSource);
}

Expand Down Expand Up @@ -240,7 +240,7 @@ export class CurrencyRepository {
return this.dao.count(options);
}

public customDataCount(options?: CurrencyEntityOptions): number {
public customDataCount(): number {
const resultSet = query.execute('SELECT COUNT(*) AS COUNT FROM "CODBEX_CURRENCY"');
if (resultSet !== null && resultSet[0] !== null) {
if (resultSet[0].COUNT !== undefined && resultSet[0].COUNT !== null) {
Expand All @@ -253,14 +253,14 @@ export class CurrencyRepository {
}

private async triggerEvent(data: CurrencyEntityEvent) {
const triggerExtensions = await extensions.loadExtensionModules("codbex-currencies/Currencies/Currency", ["trigger"]);
const triggerExtensions = await extensions.loadExtensionModules("codbex-currencies-Currencies-Currency", ["trigger"]);
triggerExtensions.forEach(triggerExtension => {
try {
triggerExtension.trigger(data);
} catch (error) {
console.error(error);
}
});
producer.topic("codbex-currencies/Currencies/Currency").send(JSON.stringify(data));
producer.topic("codbex-currencies-Currencies-Currency").send(JSON.stringify(data));
}
}
}
5 changes: 0 additions & 5 deletions codbex-currencies/gen/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<!--
The technology platform used for project codbex-currencies is Eclipse Dirigible (https://www.dirigible.io/).
All the source code is licensed under the Eclipse Public License - v 2.0 (https://www.eclipse.org/legal/epl-v20.html)
and maintained at GitHub (https://github.com/eclipse/dirigible).
-->
<!DOCTYPE html>
<html lang="en" ng-app="app" ng-controller="ApplicationController" xmlns="http://www.w3.org/1999/xhtml">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@ angular.module('page', ["ideUI", "ideView", "entityApi"])
.config(["entityApiProvider", function (entityApiProvider) {
entityApiProvider.baseUrl = "/services/ts/codbex-currencies/gen/api/Currencies/CurrencyRateService.ts";
}])
.controller('PageController', ['$scope', '$http', 'messageHub', 'entityApi', function ($scope, $http, messageHub, entityApi) {

.controller('PageController', ['$scope', 'messageHub', 'entityApi', 'Extensions', function ($scope, messageHub, entityApi, Extensions) {
//-----------------Custom Actions-------------------//
$http.get("/services/js/resources-core/services/custom-actions.js?extensionPoint=codbex-currencies-custom-action").then(function (response) {
$scope.pageActions = response.data.filter(e => e.perspective === "Currencies" && e.view === "CurrencyRate" && (e.type === "page" || e.type === undefined));
$scope.entityActions = response.data.filter(e => e.perspective === "Currencies" && e.view === "CurrencyRate" && e.type === "entity");
Extensions.get('dialogWindow', 'codbex-currencies-custom-action').then(function (response) {
$scope.pageActions = response.filter(e => e.perspective === "Currencies" && e.view === "CurrencyRate" && (e.type === "page" || e.type === undefined));
$scope.entityActions = response.filter(e => e.perspective === "Currencies" && e.view === "CurrencyRate" && e.type === "entity");
});

$scope.triggerPageAction = function (actionId) {
for (const next of $scope.pageActions) {
if (next.id === actionId) {
messageHub.showDialogWindow("codbex-currencies-custom-action", {
src: next.link,
});
break;
}
}
$scope.triggerPageAction = function (action) {
messageHub.showDialogWindow(
action.id,
{},
null,
true,
action
);
};

$scope.triggerEntityAction = function (actionId, selectedEntity) {
for (const next of $scope.entityActions) {
if (next.id === actionId) {
messageHub.showDialogWindow("codbex-currencies-custom-action", {
src: `${next.link}?id=${selectedEntity.Id}`,
});
break;
}
}
$scope.triggerEntityAction = function (action) {
messageHub.showDialogWindow(
action.id,
{
id: $scope.entity.Id
},
null,
true,
action
);
};
//-----------------Custom Actions-------------------//

Expand Down Expand Up @@ -102,7 +101,9 @@ angular.module('page', ["ideUI", "ideView", "entityApi"])
messageHub.showAlertError("CurrencyRate", `Unable to count CurrencyRate: '${response.message}'`);
return;
}
$scope.dataCount = response.data;
if (response.data) {
$scope.dataCount = response.data;
}
filter.$offset = (pageNumber - 1) * $scope.dataLimit;
filter.$limit = $scope.dataLimit;
entityApi.search(filter).then(function (response) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
angular.module('page', ["ideUI", "ideView", "entityApi"])
angular.module('page', ["ideUI", "ideView"])
.config(["messageHubProvider", function (messageHubProvider) {
messageHubProvider.eventIdPrefix = 'codbex-currencies.Currencies.CurrencyRate';
}])
.config(["entityApiProvider", function (entityApiProvider) {
entityApiProvider.baseUrl = "/services/ts/codbex-currencies/gen/api/Currencies/CurrencyRateService.ts";
}])
.controller('PageController', ['$scope', 'messageHub', 'entityApi', function ($scope, messageHub, entityApi) {
.controller('PageController', ['$scope', 'messageHub', 'ViewParameters', function ($scope, messageHub, ViewParameters) {

$scope.entity = {};
$scope.forms = {
details: {},
};

if (window != null && window.frameElement != null && window.frameElement.hasAttribute("data-parameters")) {
let dataParameters = window.frameElement.getAttribute("data-parameters");
if (dataParameters) {
let params = JSON.parse(dataParameters);
if (params?.entity?.DateFrom) {
params.entity.DateFrom = new Date(params.entity.DateFrom);
}
if (params?.entity?.DateTo) {
params.entity.DateTo = new Date(params.entity.DateTo);
}
$scope.entity = params.entity ?? {};
$scope.selectedMainEntityKey = params.selectedMainEntityKey;
$scope.selectedMainEntityId = params.selectedMainEntityId;
let params = ViewParameters.get();
if (Object.keys(params).length) {
if (params?.entity?.DateFrom) {
params.entity.DateFrom = new Date(params.entity.DateFrom);
}
if (params?.entity?.DateTo) {
params.entity.DateTo = new Date(params.entity.DateTo);
}
$scope.entity = params.entity ?? {};
$scope.selectedMainEntityKey = params.selectedMainEntityKey;
$scope.selectedMainEntityId = params.selectedMainEntityId;
}

$scope.filter = function () {
Expand Down
Loading

0 comments on commit 8507c65

Please sign in to comment.