Skip to content
Open
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
8 changes: 5 additions & 3 deletions config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"orgName": "spencerhsieh Company",
"edition": "Developer",
"orgPreferences" : {
"enabled": ["S1DesktopEnabled"]
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
}
}
}
}
52 changes: 43 additions & 9 deletions force-app/main/default/classes/ganttChart.cls
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
public with sharing class ganttChart {
@AuraEnabled
public static Map<String, Object> getChartData(String recordId, String startTime, String endTime, Integer slotSize, List<String> filterProjects, List<String> filterRoles, String filterStatus) {
public static Map<String, Object> getChartData(String recordId, String startTime, String endTime, Integer slotSize, List<String> filterProjects, List<String> filterColors, List<String> filterRoles, String filterStatus) {
Map<String, Object> data = new Map<String, Object>();
String query = 'SELECT Resource__c, Resource__r.Name, Resource__r.Active__c, Resource__r.Default_Role__c, Project__c, Project__r.Name, Project__r.Active__c, Project__r.Color__c, Start_Date__c, End_Date__c, Status__c, Effort__c FROM Allocation__c WHERE Start_Date__c <= :endDate AND End_Date__c >= :startDate AND (Project__c = NULL OR Project__r.Active__c = TRUE) AND Resource__r.Active__c = TRUE';
String query = 'SELECT Resource__c, Resource__r.Name, Resource__r.Active__c, Resource__r.Default_Role__c, Resource__r.Status__c, Project__c, Project__r.Name, Project__r.Active__c, Project__r.Color__c, Start_Date__c, End_Date__c, Status__c, Effort__c FROM Allocation__c WHERE Start_Date__c <= :endDate AND End_Date__c >= :startDate AND (Project__c = NULL OR Project__r.Active__c = TRUE) AND Resource__r.Active__c = TRUE';

List<Allocation__c> allocations = new List<Allocation__c>();
Map<String, Object> projectById = new Map<String, Object>();
Map<String, Object> resourceById = new Map<String, Object>();
Set<String> roles = new Set<String>();
//キム追記
Set<String> colors = new Set<String>();

if (!filterProjects.isEmpty()) {
query += ' AND Project__c IN :filterProjects';
}

if (!filterColors.isEmpty()) {
query += ' AND Project__r.Color__c IN :filterColors';
}
/*
if (!filterProjectRecords.isEmpty()) {
query += ' AND Project__c IN :filterProjectRecords';
Expand All @@ -26,7 +32,6 @@ public with sharing class ganttChart {

if (String.isNotEmpty(startTime) && String.isNotEmpty(endTime)) {
Date startDate = DateTime.newInstance(Long.valueOf(startTime)).date();

Date endDate = DateTime.newInstance(Long.valueOf(endTime)).date();
Integer days = startDate.daysBetween(endDate) + 1;
slotSize = Integer.valueOf(slotSize);
Expand All @@ -48,6 +53,7 @@ public with sharing class ganttChart {
'Id' => resource.get('Id'),
'Name' => resource.get('Name'),
'Default_Role__c' => resource.get('Default_Role__c'),
'Status__c' => resource.get('Status__c'),
'allocationsByProject' => new Map<String, Object>()
});
}
Expand All @@ -63,26 +69,29 @@ public with sharing class ganttChart {

// empty state on resource page
if (allocations.isEmpty() && Id.valueOf(recordId).getSobjectType().getDescribe().getName().endsWith('Resource__c')) {
Resource__c resource = [SELECT Id, Name, Active__c, Default_Role__c
Resource__c resource = [SELECT Id, Name, Active__c, Default_Role__c, Status__c
FROM Resource__c
WHERE Id = :recordId];

resourceById.put(resource.Id, new Map<String, Object> {
'Id' => resource.Id,
'Name' => resource.Name,
'Default_Role__c' => resource.Default_Role__c,
'Status__c' => resource.Status__c,
'allocationsByProject' => new Map<String, Object>()
});
}
}



// organize allocations by resource and project
for (Allocation__c allocation : allocations) {
if (!resourceById.containsKey(allocation.Resource__c)) {
resourceById.put(allocation.Resource__c, new Map<String, Object> {
'Id' => allocation.Resource__c,
'Name' => allocation.Resource__r.Name,
'Default_Role__c' => allocation.Resource__r.Default_Role__c,
'Status__c' => allocation.Resource__r.Status__c,
'allocationsByProject' => new Map<String, Object>()
});
}
Expand All @@ -96,7 +105,8 @@ public with sharing class ganttChart {

projectById.put(allocation.Project__c, new Map<String, Object> {
'Id' => allocation.Project__c,
'Name' => allocation.Project__r.Name
'Name' => allocation.Project__r.Name,
'Color'=> allocation.Project__r.Color__c
});

List<Object> projectAllocation = (List<Object>)allocationsByProject.get(allocation.Project__c);
Expand All @@ -120,12 +130,19 @@ public with sharing class ganttChart {
});

roles.add(allocation.Resource__r.Default_Role__c);
System.debug('roles' + roles);
//キム追記
colors.add(allocation.Project__r.Color__c);
System.debug('colors' + colors);
}
}

data.put('projects', projectById.values());
data.put('resources', resourceById.values());
data.put('roles', roles);
System.debug('data.putroles' + roles);
data.put('colors', colors);
System.debug('data.putcolors' + colors);

return data;
}
Expand All @@ -134,14 +151,15 @@ public with sharing class ganttChart {
public static List<Object> getResources() {
List<Object> resources = new List<Object>();

for (Resource__c r : [SELECT Id, Name, Default_Role__c
for (Resource__c r : [SELECT Id, Name, Default_Role__c, Status__c
FROM Resource__c
WHERE Active__c = true
ORDER BY Name]) {
ORDER BY Default_Role__c, Name]) {
resources.add(new Map<String, Object> {
'Id' => r.Id,
'Name' => r.Name,
'Default_Role__c' => r.Default_Role__c
'Default_Role__c' => r.Default_Role__c,
'Status__c' => r.Status__c
});
}

Expand All @@ -155,6 +173,7 @@ public with sharing class ganttChart {
WHERE Active__c = true
ORDER BY Name];
}


@AuraEnabled
public static void saveAllocation(Id allocationId, Id projectId, Id resourceId, String effort, String status, String startDate, String endDate) {
Expand Down Expand Up @@ -193,4 +212,19 @@ public with sharing class ganttChart {
public static void deleteAllocation(Id allocationId) {
delete new Allocation__c(Id = allocationId);
}



@AuraEnabled(cacheable=true)
public static List<Holidays__c> getHolidays() {
List<Holidays__c> holidays =[SELECT Id, Name,HolidayDate__c
FROM Holidays__c
];
return holidays;
}



}


33 changes: 27 additions & 6 deletions force-app/main/default/classes/tst_ganttChart.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public with sharing class tst_ganttChart {
Test.startTest();
Map<String, Object> chartData = ganttChart.getChartData(
null,
String.valueOf(dt.getTime()),
String.valueOf(dt.getTime()),
null,
null,
1,
new List<String>(),
new List<String>(),
Expand Down Expand Up @@ -78,8 +78,8 @@ public with sharing class tst_ganttChart {
Test.startTest();
Map<String, Object> chartData = ganttChart.getChartData(
r.Id,
String.valueOf(dt.getTime()),
String.valueOf(dt.getTime()),
null,
null,
1,
new List<String> { p.Id },
new List<String> { r.Default_Role__c },
Expand Down Expand Up @@ -150,11 +150,14 @@ public with sharing class tst_ganttChart {
Default_Role__c='Test Role');
insert r;

Date startDate = Date.newInstance(2023, 3, 1);
Date endDate = Date.newInstance(2023, 3, 10);

String effort = 'High';
String status = 'Active';

Test.startTest();
ganttChart.saveAllocation(null, p.Id, r.Id, effort, status, String.valueOf(dt.getTime()), String.valueOf(dt.getTime()));
ganttChart.saveAllocation(null, p.Id, r.Id, effort, status, startDate, endDate);
Test.stopTest();

List<Allocation__c> allocations = [SELECT Id, Project__c, Resource__c, Effort__c, Status__c, Start_Date__c, End_Date__c
Expand Down Expand Up @@ -184,6 +187,9 @@ public with sharing class tst_ganttChart {
String effort = 'High';
String status = 'Unavailable';

Date startDate = Date.newInstance(2023, 3, 1);
Date endDate = Date.newInstance(2023, 3, 10);

Allocation__c a = new Allocation__c(
Project__c = p.Id,
Resource__c = r.Id,
Expand All @@ -194,7 +200,7 @@ public with sharing class tst_ganttChart {
insert a;

Test.startTest();
ganttChart.saveAllocation(a.Id, null, r.Id, effort, status, String.valueOf(dt.getTime()), String.valueOf(dt.getTime()));
ganttChart.saveAllocation(a.Id, null, r.Id, effort, status, startDate, endDate);
Test.stopTest();

List<Allocation__c> allocations = [SELECT Id, Project__c, Resource__c, Effort__c, Status__c, Start_Date__c, End_Date__c
Expand Down Expand Up @@ -236,4 +242,19 @@ public with sharing class tst_ganttChart {

System.assertEquals(0, allocations.size());
}

@isTest
static void ganttChart_getHolidays() {
Date d = Date.today();
Holidays__c h = new Holidays__c(
Name='Test H',
HolidayDate__c = d);
insert h;

Test.startTest();
List<Holidays__c> holidays = ganttChart.getHolidays();
Test.stopTest();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>Status__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
Expand Down Expand Up @@ -63,7 +67,7 @@
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00h9A000000Y26d</masterLabel>
<masterLabel>00h6D000002vmrm</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
Expand Down
31 changes: 27 additions & 4 deletions force-app/main/default/lwc/gantt_chart/gantt_chart.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,31 @@
}

.lwc-timeline_day {
min-width: 50px;
border-bottom: 1px solid #dddbda;
border-right: 1px solid #dddbda;
border-top: 1px solid #dddbda;
width: 50px;
text-align: center;
padding-right: 1px;
/* padding-right: 1px; */
}

.lwc-timeline_month-container>div{
position: sticky;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1;




}
.lwc-timeline_month-container:first-child .lwc-timeline_day:first-child,
.lwc-timeline_month-container:only-child .lwc-timeline_day:first-child {

border-left: 3px solid #dddbda;

}

.lwc-timeline_month-container:last-child .lwc-timeline_day:last-child,
Expand All @@ -33,7 +49,9 @@
}

.lwc-timeline_day.lwc-is-week-end {
border-right: 3px solid #dddbda;
background: rgba(221, 63, 14, 0.1);
border-top: 3px solid #dd2929;
margin-top: 3px;
padding-right: 0;

}
Expand All @@ -44,6 +62,11 @@
margin-top: 3px;
}

.lwc-timeline_day.lwc-is-holiday {
background: rgba(221, 63, 14, 0.1);
border-top: 3px solid #dd2929;
margin-top: 3px;
}
.lwc-timeline_month {
border-radius: .25rem;
}
Expand Down
Loading