Skip to content

Commit 40cb767

Browse files
Farcasuttrrenty
andauthored
Status picker breaks if installed by user without programming rights #177 (#205)
* Update the Status property Sheet accordingly. * Update the task macro status parameter that also relies on the order of the statuses. * Update the list<taskstatus> edit vm to use the script service method * Update the task template to be up to date with the changed TaskManagerClass * [Misc] Set the livedata filters to take the order of statuses into consideration --------- Co-authored-by: Teodor Caras <[email protected]>
1 parent 8119491 commit 40cb767

File tree

8 files changed

+73
-25
lines changed

8 files changed

+73
-25
lines changed

application-task-api/src/main/java/com/xwiki/task/script/TaskScriptService.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@
2121

2222
import java.util.Collections;
2323
import java.util.List;
24+
import java.util.Objects;
25+
import java.util.stream.Collectors;
2426

2527
import javax.inject.Inject;
2628
import javax.inject.Named;
2729
import javax.inject.Singleton;
2830

31+
import org.slf4j.Logger;
2932
import org.xwiki.component.annotation.Component;
3033
import org.xwiki.job.Job;
3134
import org.xwiki.job.JobException;
3235
import org.xwiki.job.JobExecutor;
3336
import org.xwiki.model.reference.DocumentReference;
3437
import org.xwiki.model.reference.WikiReference;
38+
import org.xwiki.query.Query;
39+
import org.xwiki.query.QueryException;
40+
import org.xwiki.query.QueryManager;
3541
import org.xwiki.script.service.ScriptService;
3642
import org.xwiki.security.authorization.ContextualAuthorizationManager;
3743
import org.xwiki.security.authorization.Right;
@@ -66,6 +72,12 @@ public class TaskScriptService implements ScriptService
6672
@Inject
6773
private JobExecutor jobExecutor;
6874

75+
@Inject
76+
private QueryManager queryManager;
77+
78+
@Inject
79+
private Logger logger;
80+
6981
/**
7082
* @return the configuration of the application.
7183
*/
@@ -119,4 +131,23 @@ public List<DocumentReference> getPagesWithIncompleteTaskMacros()
119131
return Collections.emptyList();
120132
}
121133
}
134+
135+
/**
136+
* @return a list of statuses sorted by their order property.
137+
*/
138+
public List<String> getSortedStatuses()
139+
{
140+
141+
try {
142+
Query query = queryManager.createQuery("select prop1.value from BaseObject as obj, "
143+
+ "StringProperty as prop1, IntegerProperty as prop2 where obj.className='TaskManager.StatusClass' and "
144+
+ "obj.id=prop1.id.id and prop1.id.name='status' and obj.id=prop2.id.id and prop2.id.name='order' "
145+
+ "order by prop2.value", Query.HQL);
146+
List<String> results = query.execute().stream().map(Objects::toString).collect(Collectors.toList());
147+
return results;
148+
} catch (QueryException e) {
149+
logger.error("Failed to retrieve the statuses.", e);
150+
throw new RuntimeException(e);
151+
}
152+
}
122153
}

application-task-api/src/main/resources/templates/html_displayer/java.util.list(com.xwiki.task.taskstatus)/edit.vm

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@
1818
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
1919
## ---------------------------------------------------------------------------
2020
#template("pickers_macros.vm")
21-
#set ($st = "select prop1.value from BaseObject as obj, StringProperty as prop1, IntegerProperty as prop2
22-
where obj.className='TaskManager.StatusClass'
23-
and obj.id=prop1.id.id
24-
and prop1.id.name='status'
25-
and obj.id=prop2.id.id
26-
and prop2.id.name='order'
27-
order by prop2.value")
28-
#set ($results = $services.query.hql($st).execute())
2921
#set ($options = [])
3022
#set ($translationKeyPrefix = 'TaskManager.TaskManagerClass_status_')
31-
#foreach ($status in $results)
23+
#foreach ($status in $services.task.getSortedStatuses())
3224
#set ($translationKey = $translationKeyPrefix + $status)
3325
#if ($services.localization.get($translationKey))
3426
#set ($label = $services.localization.render($translationKey))

application-task-api/src/main/resources/templates/html_displayer/taskstatus/edit.vm

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,13 @@
1717
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1818
## 02110-1301 USA, or see the FSF site: http://www.fsf.org.
1919
## ---------------------------------------------------------------------------
20-
#set ($st = "select prop1.value from BaseObject as obj, StringProperty as prop1, IntegerProperty as prop2
21-
where obj.className='TaskManager.StatusClass'
22-
and obj.id=prop1.id.id
23-
and prop1.id.name='status'
24-
and obj.id=prop2.id.id
25-
and prop2.id.name='order'
26-
order by prop2.value")
27-
#set ($results = $services.query.hql($st).execute())
2820
<select
2921
#foreach ($parameter in $displayer.parameters.entrySet())
3022
$escapetool.xml($parameter.key)="$!escapetool.xml($parameter.value)"
3123
#end
3224
>
3325
#set ($translationKeyPrefix = 'TaskManager.TaskManagerClass_status_')
34-
#foreach ($item in $results)
26+
#foreach ($item in $services.task.getSortedStatuses())
3527
#set ($translationKey = $translationKeyPrefix + $item)
3628
#if ($services.localization.get($translationKey))
3729
#set ($label = $services.localization.render($translationKey))

application-task-ui/src/main/resources/TaskManager/PropertySheets/Status.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
#set($propertyClass = $object.getxWikiClass().get($name))
4444
#set($existingValue = $object.getValue('status'))
4545
&lt;select size="1" name="TaskManager.TaskManagerClass_0_status" id="TaskManager.TaskManagerClass_0_status"&gt;
46-
#foreach($rValue in $propertyClass.mapValues.entrySet())
47-
#set($key = "TaskManager.TaskManagerClass_status_$rValue.key")
46+
#foreach($rValue in $services.task.getSortedStatuses())
47+
#set($key = "TaskManager.TaskManagerClass_status_$rValue")
4848
#set($translation = $services.localization.render($key))
49-
&lt;option value="$escapetool.xml($rValue.key)" #if($existingValue == $rValue.key) selected='selected' #end&gt;
49+
&lt;option value="$escapetool.xml($rValue)" #if($existingValue == $rValue) selected='selected' #end&gt;
5050
#if ($translation == $key)
51-
$escapetool.xml($rValue.key)
51+
$escapetool.xml($rValue)
5252
#else
5353
$escapetool.xml($translation)
5454
#end

application-task-ui/src/main/resources/TaskManager/TaskManagerClass.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
<separators/>
358358
<size>1</size>
359359
<sort>none</sort>
360-
<sql>select prop1.value, prop1.value from BaseObject as obj, StringProperty as prop1, IntegerProperty as prop2 where obj.className='TaskManager.StatusClass' and obj.id=prop1.id.id and prop1.id.name='status' and obj.id=prop2.id.id and prop2.id.name='order' order by prop2.value</sql>
360+
<sql/>
361361
<unmodifiable>0</unmodifiable>
362362
<validationMessage/>
363363
<validationRegExp/>

application-task-ui/src/main/resources/TaskManager/TaskManagerTemplate.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@
546546
<separators/>
547547
<size>1</size>
548548
<sort>none</sort>
549-
<sql>select prop1.value, prop1.value from BaseObject as obj, StringProperty as prop1, IntegerProperty as prop2 where obj.className='TaskManager.StatusClass' and obj.id=prop1.id.id and prop1.id.name='status' and obj.id=prop2.id.id and prop2.id.name='order' order by prop2.value</sql>
549+
<sql/>
550550
<unmodifiable>0</unmodifiable>
551551
<validationMessage/>
552552
<validationRegExp/>

application-task-ui/src/main/resources/TaskManager/TaskReportMacro.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@
294294
#foreach ($creatorVal in $creator.split('\s*,\s*'))
295295
#set ($livedataFilters = "${livedataFilters}&amp;reporter=${creatorVal}")
296296
#end
297+
## Define the filter options for the status that need to be ordered by priority.
298+
#set ($statusOptions = [{"value": "", "label": $services.localization.render('livedata.filter.list.emptyLabel')}])
299+
#foreach($rValue in $services.task.getSortedStatuses())
300+
#set($key = "TaskManager.TaskManagerClass_status_$rValue")
301+
#set($translation = $services.localization.render($key))
302+
#if ($translation == $key)
303+
#set ($discard = $statusOptions.add({ "value": $rValue, "label": $rValue}))
304+
#else
305+
#set ($discard = $statusOptions.add({ "value": $rValue, "label": $translation}))
306+
#end
307+
#end
297308
## Define livedata cfg, setting all the properties to invisible by default and changing it later based on what columns the user chose.
298309
#set ($livedataCfg = {
299310
"query": {
@@ -336,7 +347,11 @@
336347
},
337348
{
338349
"id": "status",
339-
"visible": false
350+
"visible": true,
351+
"filter": {
352+
"id": "list",
353+
"options": $statusOptions
354+
}
340355
}
341356
]
342357
}

application-task-ui/src/main/resources/TaskManager/WebHomeSheet.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444

4545
{{taskgantt readonly="false"/}}
4646

47+
#set ($statusOptions = [{"value": "", "label": $services.localization.render('livedata.filter.list.emptyLabel')}])
48+
#foreach($rValue in $services.task.getSortedStatuses())
49+
#set($key = "TaskManager.TaskManagerClass_status_$rValue")
50+
#set($translation = $services.localization.render($key))
51+
#if ($translation == $key)
52+
#set ($discard = $statusOptions.add({ "value": $rValue, "label": $rValue}))
53+
#else
54+
#set ($discard = $statusOptions.add({ "value": $rValue, "label": $translation}))
55+
#end
56+
#end
57+
4758
{{liveData
4859
id="taskmanager"
4960
properties="name,project,status,severity,reporter,assignee,duedate,_actions"
@@ -59,6 +70,13 @@
5970
"id": "link",
6071
"propertyHref": "doc.url"
6172
}
73+
},
74+
{
75+
"id": "status",
76+
"filter": {
77+
"id": "list",
78+
"options": $jsontool.serialize($statusOptions)
79+
}
6280
}
6381
]
6482
}

0 commit comments

Comments
 (0)