Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - APP + API - Nueva página de inicio #159

Merged
merged 83 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
9c54353
wip
juanSTIC Dec 4, 2023
c89a8c3
wip
juanSTIC Dec 4, 2023
91e2708
tunning
juanSTIC Dec 4, 2023
c6e261b
tune
juanSTIC Dec 4, 2023
c5e3209
Merge branch 'reporting' into enhancement/home2
juanSTIC Jun 4, 2024
a93980c
Merge branch 'reporting' into enhancement/home2
juanSTIC Jun 13, 2024
c820198
wip
juanSTIC Jun 14, 2024
79c66b0
wip
juanSTIC Jun 17, 2024
cd4c975
Merge branch 'reporting' into enhancement/home2
juanSTIC Jun 24, 2024
02cc085
sorted & optimize
juanSTIC Jun 24, 2024
a3f3cf5
card mode & persist & public URL
juanSTIC Jun 25, 2024
04d05b9
icon colors
juanSTIC Jun 25, 2024
fe6e37b
defaulr route
juanSTIC Jun 25, 2024
e0cedcf
get user info in all cases
juanSTIC Jun 25, 2024
6a33dd8
description
juanSTIC Jun 25, 2024
9d0417e
clone reports
juanSTIC Jun 26, 2024
509e6d3
new date at clone & filter after clone
juanSTIC Jun 26, 2024
fe495bc
date created & copy URL
juanSTIC Jun 27, 2024
b289d70
wip
juanSTIC Jun 28, 2024
01335e1
wip
juanSTIC Jun 28, 2024
55d90d1
localize
juanSTIC Jun 28, 2024
619cebe
tunning
juanSTIC Jun 28, 2024
59b0e92
Merge branch 'reporting' into enhancement/home2
juanSTIC Jul 15, 2024
3f1da8a
format
juanSTIC Jul 15, 2024
71e8b12
report visbility & filter indicator
juanSTIC Jul 15, 2024
1d35a4d
label translations
juanSTIC Jul 15, 2024
71bf4a3
create new report button & add createAt
juanSTIC Jul 15, 2024
25a1e4d
tunning
juanSTIC Jul 15, 2024
f738382
tittle short
juanSTIC Jul 16, 2024
9b2b111
title edit in card
juanSTIC Jul 16, 2024
30bfc95
reaply filter after delete
juanSTIC Jul 16, 2024
7b1b169
Merge branch 'reporting' into enhancement/home2
juanSTIC Jul 24, 2024
0c38015
remove todo
juanSTIC Aug 19, 2024
0dfe3a0
normalize buttons
juanSTIC Aug 19, 2024
9097c11
edit type in panel
juanSTIC Aug 19, 2024
b29f460
fine type change
juanSTIC Aug 20, 2024
d96545e
edit fix
juanSTIC Aug 20, 2024
e50d9c6
remove reoerder after change type
juanSTIC Aug 21, 2024
c1aa9ab
get DS name
juanSTIC Aug 21, 2024
26a9f11
ds info & change type in table
juanSTIC Aug 21, 2024
3b30762
modifiedAt, & some enhancements
juanSTIC Aug 22, 2024
462dcd6
label groups visualization
juanSTIC Aug 22, 2024
a7db4b2
reorde toolbar
juanSTIC Aug 23, 2024
3e9542c
wip
juanSTIC Sep 3, 2024
02fe2bc
table name edit & show descrption
juanSTIC Sep 3, 2024
c739b9f
enhancement events
juanSTIC Sep 3, 2024
72cb1c0
auto active type component
juanSTIC Sep 3, 2024
061394b
filter tags enhancements
juanSTIC Sep 4, 2024
b5f4132
group indicator & icon
juanSTIC Sep 4, 2024
271239e
fix group filter
juanSTIC Sep 4, 2024
536ea20
reorder
juanSTIC Sep 4, 2024
d81dbbf
fix name deleting contents
juanSTIC Sep 5, 2024
e6d9a0f
do not sort after filter
juanSTIC Sep 5, 2024
5c184ff
i18n fixes
juanSTIC Sep 5, 2024
e2fd44e
icon change
juanSTIC Sep 5, 2024
1ba4c90
document
juanSTIC Sep 5, 2024
62dccf9
format files
juanSTIC Sep 5, 2024
fee35aa
Merge branch 'reporting' into enhancement/home2
juanSTIC Sep 5, 2024
997c52c
fix labels
juanSTIC Sep 6, 2024
0152a66
fix label
juanSTIC Sep 6, 2024
9be2169
new type filter
juanSTIC Sep 6, 2024
0c5231e
remove filters
juanSTIC Sep 6, 2024
866bad4
links enhancements
juanSTIC Sep 6, 2024
c8a910a
vsual changes
juanSTIC Sep 6, 2024
cfc0b4f
fix private edition sort
juanSTIC Sep 6, 2024
61c2e41
ensure visibility to no admin users
juanSTIC Sep 6, 2024
3c0bd54
no admin users can see groups
juanSTIC Sep 6, 2024
4b1476e
show author to no admin users
juanSTIC Sep 6, 2024
176cd39
no admin can clone
juanSTIC Sep 6, 2024
867fd97
oficial colors
juanSTIC Sep 6, 2024
5c6cf5b
fix public url copy
juanSTIC Sep 9, 2024
0b8800b
rename component
juanSTIC Sep 10, 2024
81e0a59
rm console log
juanSTIC Sep 10, 2024
747e33f
Improving translation
jalbaiges Sep 10, 2024
fb70175
Improving translation
jalbaiges Sep 10, 2024
db46e77
Improving translation
jalbaiges Sep 10, 2024
8e2a5b1
Improving translation
jalbaiges Sep 10, 2024
41b50ca
avoid no admin users change type to public (shared)
juanSTIC Sep 12, 2024
5a61851
fix https://github.com/SinergiaTIC/SinergiaDA/pull/159#pullrequestrev…
juanSTIC Sep 12, 2024
be5fdad
Improving translation
jalbaiges Sep 13, 2024
42a8f71
Improving translation
jalbaiges Sep 13, 2024
8b6a5e8
Improving translation
jalbaiges Sep 13, 2024
bf40db3
Improving translation
jalbaiges Sep 13, 2024
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
273 changes: 207 additions & 66 deletions eda/eda_api/lib/module/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,23 @@ const eda_api_config = require('../../../config/eda_api_config');
export class DashboardController {
static async getDashboards(req: Request, res: Response, next: NextFunction) {
try {
let admin,
privates,
group,
publics,
shared = []
const groups = await Group.find({ users: { $in: req.user._id } }).exec()
const isAdmin = groups.filter(g => g.role === 'EDA_ADMIN_ROLE').length > 0
const isDataSourceCreator = groups.filter(g => g.name === 'EDA_DATASOURCE_CREATOR').length > 0
let admin, privates, group, publics, shared = [];
const groups = await Group.find({ users: { $in: req.user._id } }).exec();
const isAdmin = groups.filter(g => g.role === 'EDA_ADMIN_ROLE').length > 0;
const isDataSourceCreator = groups.filter(g => g.name === 'EDA_DATASOURCE_CREATOR').length > 0;

if (isAdmin) {
admin = await DashboardController.getAllDashboardToAdmin()
publics = admin[0]
privates = admin[1]
group = admin[2]
shared = admin[3]
[publics, privates, group, shared] = await DashboardController.getAllDashboardToAdmin();
} else {
privates = await DashboardController.getPrivateDashboards(req)
group = await DashboardController.getGroupsDashboards(req)
publics = await DashboardController.getPublicsDashboards()
shared = await DashboardController.getSharedDashboards()
privates = await DashboardController.getPrivateDashboards(req);
group = await DashboardController.getGroupsDashboards(req);
publics = await DashboardController.getPublicsDashboards();
shared = await DashboardController.getSharedDashboards();
}

// Asegurarse de que la información del grupo esté incluida para dashboards de tipo "group"
group = await DashboardController.addGroupInfo(group);

return res.status(200).json({
ok: true,
dashboards: privates,
Expand All @@ -43,22 +39,34 @@ export class DashboardController {
shared,
isAdmin,
isDataSourceCreator
})
});
} catch (err) {
console.log(err)
next(new HttpException(400, 'Some error ocurred loading dashboards'))
console.log(err);
next(new HttpException(400, 'Some error occurred loading dashboards'));
}
}

static async addGroupInfo(dashboards) {
for (const dashboard of dashboards) {
if (dashboard.group && Array.isArray(dashboard.group)) {
dashboard.group = await Group.find({ _id: { $in: dashboard.group } }, 'name').exec();
}
}
return dashboards;
}

static async getPrivateDashboards(req: Request) {
try {
const dashboards = await Dashboard.find(
{ user: req.user._id },
'config.title config.visible config.tag config.onlyIcanEdit'
).exec()
'config.title config.visible config.tag config.onlyIcanEdit config.description config.createdAt config.modifiedAt config.ds user'
).populate('user','name').exec()
const privates = []
for (const dashboard of dashboards) {
if (dashboard.config.visible === 'private') {
// Obtain the name of the data source
dashboard.config.ds.name = (await DataSource.findById(dashboard.config.ds._id, 'ds.metadata.model_name').exec())?.ds?.metadata?.model_name ?? 'N/A';

privates.push(dashboard)
}
}
Expand All @@ -72,42 +80,33 @@ export class DashboardController {
try {
const userGroups = await Group.find({
users: { $in: req.user._id }
}).exec()
}).exec();
const dashboards = await Dashboard.find(
{ group: { $in: userGroups.map(g => g._id) } },
'config.title config.visible group config.tag config.onlyIcanEdit'
).exec()
const groupDashboards = []
for (let i = 0, n = dashboards.length; i < n; i += 1) {
const dashboard = dashboards[i]
for (const dashboardGroup of dashboard.group) {
//dashboard.group = groups.filter(g => JSON.stringify(g._id) === JSON.stringify(group));
for (const userGroup of userGroups) {
if (
JSON.stringify(userGroup._id) === JSON.stringify(dashboardGroup)
) {
groupDashboards.push(dashboard)
}
}
}
}
return groupDashboards
'config.title config.visible group config.tag config.onlyIcanEdit config.description config.createdAt config.ds user'
).populate('user','name').exec()

// Añadir información de grupo aquí también
return DashboardController.addGroupInfo(dashboards);
} catch (err) {
console.log(err)
throw new HttpException(400, 'Error loading groups dashboards')
console.log(err);
throw new HttpException(400, 'Error loading groups dashboards');
}
}

static async getPublicsDashboards() {
try {
const dashboards = await Dashboard.find(
{},
'config.title config.visible config.tag config.onlyIcanEdit'
).exec()
'config.title config.visible config.tag config.onlyIcanEdit config.description config.createdAt config.modifiedAt config.ds user'
).populate('user','name').exec()
const publics = []

for (const dashboard of dashboards) {
if (dashboard.config.visible === 'public') {
// Obtain the name of the data source
dashboard.config.ds.name = (await DataSource.findById(dashboard.config.ds._id, 'ds.metadata.model_name').exec())?.ds?.metadata?.model_name ?? 'N/A';

publics.push(dashboard)
}
}
Expand All @@ -121,11 +120,14 @@ export class DashboardController {
try {
const dashboards = await Dashboard.find(
{},
'config.title config.visible config.tag config.onlyIcanEdit'
).exec()
'config.title config.visible config.tag config.onlyIcanEdit config.description config.createdAt config.modifiedAt config.ds user'
).populate('user','name').exec()
const shared = []
for (const dashboard of dashboards) {
if (dashboard.config.visible === 'shared') {
// Obtain the name of the data source
dashboard.config.ds.name = (await DataSource.findById(dashboard.config.ds._id, 'ds.metadata.model_name').exec())?.ds?.metadata?.model_name ?? 'N/A';

shared.push(dashboard)
}
}
Expand All @@ -137,36 +139,68 @@ export class DashboardController {

static async getAllDashboardToAdmin() {
try {


// Define the default date to be used for both createdAt and modifiedAt fields
const defaultDate = new Date('2024-01-01T00:00:00.000Z');

// First, update all documents that don't have a createdAt field
// This operation sets a default createdAt date for all dashboards missing this field
const createdAtUpdateResult = await Dashboard.updateMany(
{ 'config.createdAt': { $exists: false } },
{ $set: { 'config.createdAt': defaultDate } }
);

// Then, update all documents that don't have a modifiedAt field
// If createdAt exists, use its value; otherwise, use the default date
const modifiedAtUpdateResult = await Dashboard.updateMany(
{ 'config.modifiedAt': { $exists: false } },
[
{
$set: {
'config.modifiedAt': {
$ifNull: ['$config.createdAt', defaultDate]
}
}
}
]
);



const dashboards = await Dashboard.find(
{},
'user config.title config.visible group config.tag config.onlyIcanEdit'
'user config.title config.visible group config.tag config.onlyIcanEdit config.description config.createdAt config.modifiedAt config.ds'
).exec()
const publics = []
const privates = []
const groups = []
const shared = []

for (const dashboard of dashboards) {
// Buscar información del usuario para todos los dashboards
dashboard.user = await User.findById(
{ _id: dashboard.user },
'name'
).exec()
if (dashboard.user == null) {
dashboard.user = new User({
name: 'N/A',
email: '',
password: '',
img: '',
role: '',
active: ''
})
}

// Obtain the name of the data source
dashboard.config.ds.name = (await DataSource.findById(dashboard.config.ds._id, 'ds.metadata.model_name').exec())?.ds?.metadata?.model_name ?? 'N/A';
switch (dashboard.config.visible) {
case 'public':
publics.push(dashboard)
break
case 'private':
dashboard.user = await User.findById(
{ _id: dashboard.user },
'name'
).exec()
if (dashboard.user == null) {
dashboard.user = new User(
{
name: 'N/A',
email: '',
password: '',
img: '',
role: '',
active: ''
})
};
privates.push(dashboard)
break
case 'group':
Expand All @@ -178,7 +212,7 @@ export class DashboardController {
break
}
}

return [publics, privates, groups, shared]
} catch (err) {
throw new HttpException(400, 'Error loading dashboards for admin')
Expand Down Expand Up @@ -395,12 +429,17 @@ export class DashboardController {
new HttpException(400, 'Dashboard not exist with this id')
)
}

const createdAt=dashboard.config.createdAt
dashboard.config = body.config
dashboard.config.createdAt = createdAt
dashboard.group = body.group
/**avoid dashboards without name */
if (dashboard.config.title === null) { dashboard.config.title = '-' };


// Update modifiedAt with current date and time
dashboard.config.modifiedAt = new Date();


dashboard.save((err, dashboard) => {
if (err) {
return next(new HttpException(500, 'Error updating dashboard'))
Expand All @@ -413,6 +452,62 @@ export class DashboardController {
next(err)
}
}

/**
* Updates a specific field of a dashboard.
*
* @param {Request} req - Express request object
* @param {Response} res - Express response object
* @param {NextFunction} next - Express next middleware function
*
* @description
* Expects 'id' in req.params and 'data' (containing 'key' and 'newValue') in req.body.
* If 'config.visible' is updated to a value other than 'group', 'group' is set to an empty array.
*
* @throws {HttpException} 400 for update errors, 404 if dashboard not found
*/
static async updateSpecific(req: Request, res: Response, next: NextFunction) {
try {
const { id } = req.params;
const { data } = req.body;
const { key, newValue } = data;

let updateObj: any = { [key]: newValue };

if (key === 'config.visible' && newValue !== 'group') {
updateObj = {
...updateObj,
group: []
};
}

Dashboard.findByIdAndUpdate(
id,
{ $set: updateObj },
{ new: true, runValidators: true },
(err, dashboard) => {
if (err) {
return next(
new HttpException(
400,
'Some error occurred while updating the dashboard'
)
);
}

if (!dashboard) {
return next(
new HttpException(404, 'Dashboard not found with this id')
);
}

return res.status(200).json({ ok: true, dashboard });
}
);
} catch (err) {
next(err);
}
}

static async delete(req: Request, res: Response, next: NextFunction) {
let options: QueryOptions = {}
Expand Down Expand Up @@ -1410,6 +1505,52 @@ export class DashboardController {
data[1] = newRows
}
}

/**
* Clones an existing dashboard.
*
* @param req - Express request object containing the dashboard ID to clone
* @param res - Express response object
* @param next - Express next function
* @returns A Promise that resolves with the cloned dashboard or rejects with an error
*/
static async clone(req: Request, res: Response, next: NextFunction) {
try {
const dashboardId = req.params.id;
console.log('Attempting to clone dashboard with ID:', dashboardId);

// Find the original dashboard by ID
const originalDashboard = await Dashboard.findById(dashboardId).exec();

if (!originalDashboard) {
console.log('Original dashboard not found');
return next(new HttpException(404, 'Dashboard not found'));
}

// Create a new dashboard object with cloned properties
const clonedDashboard: IDashboard = new Dashboard({
config: {
...originalDashboard.config,
title: `${originalDashboard.config.title} copy`, // Append 'copy' to the title
createdAt: new Date(),
modifiedAt: new Date()
},
user: req.user._id, // Set the current user as the owner of the cloned dashboard
group: originalDashboard.group // Maintain the same group permissions
});


// Save the cloned dashboard to the database
const savedDashboard = await clonedDashboard.save();
console.log('Cloned dashboard saved:', savedDashboard);

// Return the saved cloned dashboard with a 201 (Created) status
return res.status(201).json({ ok: true, dashboard: savedDashboard });
} catch (err) {
console.error('Error cloning dashboard:', err);
next(new HttpException(500, 'Error cloning dashboard'));
}
}

static async cleanDashboardCache(
req: Request,
Expand Down
4 changes: 4 additions & 0 deletions eda/eda_api/lib/module/dashboard/dashboard.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ router.put('/:id', authGuard, DashboardController.update);

router.delete('/:id', authGuard, DashboardController.delete);

/*SDA CUSTOM*/ router.put('/:id/updateSpecific', authGuard, DashboardController.updateSpecific);

/*SDA CUSTOM*/ router.post('/:id/clone', authGuard, DashboardController.clone);

export default router;
Loading