Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions api/component-library/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"routes": [
{
"method": "GET",
"path": "/component-library",
"handler": "component-library.find",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/component-library",
"handler": "component-library.create",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/component-library/:id",
"handler": "component-library.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/component-library/:id",
"handler": "component-library.delete",
"config": {
"policies": []
}
}
]
}
37 changes: 37 additions & 0 deletions api/component-library/controllers/component-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

const { sanitizeEntity } = require("strapi-utils");
const { throwErrors } = require('../../../config/toolkits');
const { ERROR_TYPE } = require('../../../config/constants');

module.exports = {
async delete(ctx) {
const { id } = ctx.params;
try{
const res = await strapi.services['component-library'].delete({ id });
try{
await strapi.services['user-components'].delete({ library: id });
} catch (error) {
strapi.log.error('user-component delete failed', error);
throwErrors('user-component delete failed.', ERROR_TYPE.badRequest);
}
return sanitizeEntity(res, {model: strapi.models['component-library']});

}catch(error) {
strapi.log.error('component-library delete failed', error);
throwErrors('component-library delete failed.', ERROR_TYPE.badRequest);
}

return sanitizeEntity(res, {model: strapi.models['component-library']});;
}
};
12 changes: 12 additions & 0 deletions api/component-library/models/component-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
module.exports = {};
81 changes: 81 additions & 0 deletions api/component-library/models/component-library.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"kind": "collectionType",
"collectionName": "component_library",
"info": {
"name": "Component-Library",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"comment": "",
"draftAndPublish": true
},
"attributes": {
"name": {
"type": "string",
"required": true
},
"packageName": {
"type": "string",
"required": true
},
"version": {
"type": "string",
"required": true
},
"framework": {
"type": "enumeration",
"enum": [
"Html",
"Angular",
"React",
"Vue"
],
"required": true
},
"script": {
"type": "string"
},
"css": {
"type": "json"
},
"description": {
"type": "string"
},
"thumbnail": {
"type": "string"
},
"isDefault": {
"type": "boolean",
"default": false
},
"isOfficial": {
"type": "boolean",
"default": false
},
"public": {
"type": "integer",
"default": 0,
"required": false
},
"createdBy": {
"plugin": "users-permissions",
"model": "user"
},
"updatedBy": {
"plugin": "users-permissions",
"model": "user"
},
"public_scope_tenants": {
"collection": "tenant",
"via": "component_library",
"collectionName": "component_library_tenant",
"dominant": true
},
"materials": {
"via": "component_library",
"collection": "materials"
}
}
}
12 changes: 12 additions & 0 deletions api/component-library/services/component-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
module.exports = {};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"material": {
"model": "materials"
},
"materials": {
"collection": "materials",
"via": "material_category_relations",
"collectionName": "materials__material_category_relations",
"dominant": true
},
"category_code": {
"type": "string",
"required": true
Expand Down
10 changes: 7 additions & 3 deletions api/materials/models/materials.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"type": "json"
},
"user_components": {
"type": "string"
"via": "materials",
"collection": "user-components",
"dominant": true
},
"latest": {
"model": "material-histories"
Expand Down Expand Up @@ -92,10 +94,12 @@
},
"material_category_relations": {
"collection": "material-category-relation",
"via": "material"
"via": "materials"
},
"component_library": {
"type": "string"
"collection": "component-library",
"via": "materials",
"dominant": true
}
}
}
4 changes: 4 additions & 0 deletions api/tenant/models/tenant.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"user_components": {
"via": "public_scope_tenants",
"collection": "user-components"
},
"component_library": {
"via": "public_scope_tenants",
"collection": "component-library"
}
}
}
39 changes: 1 addition & 38 deletions api/user-components/controllers/user-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ const {
const idRegExp = /^[0-9]+$/; // Tips: 非必要情况下正则不要用g参数;如果必须使用,需要尽量限制使用范围,不要设为全局变量。

module.exports = {
async find(ctx) {
const { list } = await findAllMaterial(ctx.session.user, ctx.request.query, 'user-components', 'user_components', [
'createdBy'
]);
return list.map((item) =>
sanitizeEntity(
{ ...item, createdBy: filterUserField(item.createdBy) },
{ model: strapi.models['user-components'] }
)
);
},

async pagination(ctx) {
const { list, total } = await findAllMaterial(
Expand All @@ -59,33 +48,7 @@ module.exports = {
const { list } = await findAllMaterial(ctx.session.user, ctx.request.query, 'user-components', 'user_components');
return list.length;
},

async update(ctx) {
const { id } = ctx.params;
const newData = { ...ctx.request.body };

let currentPublicScope = newData.public;
if (!isTruthy(currentPublicScope)) {
currentPublicScope = (await strapi.services['user-components'].findOne({ id })).public;
}

handlePublicScope(currentPublicScope, newData);
handleTinyReserved(ctx.session.user, newData);

const component = await strapi.services['user-components'].update({ id }, newData);
return sanitizeEntity(component, { model: strapi.models['user-components'] });
},

async create(ctx) {
const data = { ...ctx.request.body };

handlePublicScope(data.public, data);
handleTinyReserved(ctx.session.user, data, true);

const component = await strapi.services['user-components'].create(data);
return sanitizeEntity(component, { model: strapi.models['user-components'] });
},


async associated(ctx) {
const { id } = ctx.params;
if (!idRegExp.test(id)) {
Expand Down
4 changes: 4 additions & 0 deletions api/user-components/models/user-components.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
},
"library": {
"type": "integer"
},
"materials": {
"via": "user_components",
"collection": "materials"
}
}
}
Loading