Skip to content

Commit

Permalink
self-xdsd#262 "Tasks" card improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
criske committed Jan 10, 2021
1 parent 2d3f846 commit 34675b4
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 8 deletions.
258 changes: 258 additions & 0 deletions src/main/java/com/selfxdsd/selfweb/api/AllTasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.selfweb.api;

import com.selfxdsd.api.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.Iterator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
* Lists all Contract tasks, active and invoiced, ordered by newest assignment
* date.
* <br/>
* Should be used only for listing via its iterator, otherwise will
* throw UnsupportedOperationException.
* @author criske
* @version $Id$
* @since 0.0.1
*/
class AllTasks implements Tasks {

/**
* Contract.
*/
private final Contract ofContract;

/**
* Ctor.
*
* @param ofContract Contract.
*/
AllTasks(final Contract ofContract) {
this.ofContract = ofContract;
}

@Override
public Task getById(final String issueId,
final String repoFullName,
final String provider) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Task register(final Issue issue) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Task assign(final Task task,
final Contract contract,
final int days) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Task unassign(final Task task) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Tasks ofProject(final String repoFullName,
final String repoProvider) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Tasks ofContributor(final String username, final String provider) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Tasks ofContract(final Contract.Id id) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Tasks unassigned() {
throw new UnsupportedOperationException("Not supported");
}

@Override
public boolean remove(final Task task) {
throw new UnsupportedOperationException("Not supported");
}

@Override
public Iterator<Task> iterator() {
return Stream.concat(
StreamSupport.stream(this.ofContract
.tasks().spliterator(), false)
.<Task>map(StatusTask.Active::new),
StreamSupport.stream(this.ofContract
.invoices().spliterator(), false)
.flatMap(invoice -> StreamSupport
.stream(invoice.tasks().spliterator(), false)
.map(invoicedTask -> new StatusTask
.Closed(invoicedTask.task(), invoice.invoiceId()))))
.sorted(Comparator.comparing(Task::assignmentDate))
.iterator();
}

/**
* Status task. This can be active or closed.
*/
abstract static class StatusTask implements Task {

/**
* Delegate.
*/
private final Task delegate;

/**
* Ctor.
*
* @param delegate Delegate.
*/
protected StatusTask(final Task delegate) {
this.delegate = delegate;
}

@Override
public String issueId() {
return delegate.issueId();
}

@Override
public String role() {
return delegate.role();
}

@Override
public Issue issue() {
return delegate.issue();
}

@Override
public Project project() {
return delegate.project();
}

@Override
public Contributor assignee() {
return delegate.assignee();
}

@Override
public Contract contract() {
return delegate.contract();
}

@Override
public Task assign(final Contributor contributor) {
return delegate.assign(contributor);
}

@Override
public Task unassign() {
return delegate.unassign();
}

@Override
public Resignations resignations() {
return delegate.resignations();
}

@Override
public LocalDateTime assignmentDate() {
return delegate.assignmentDate();
}

@Override
public LocalDateTime deadline() {
return delegate.deadline();
}

@Override
public BigDecimal value() {
return delegate.value();
}

@Override
public int estimation() {
return delegate.estimation();
}

/**
* Active task status.
*/
static class Active extends StatusTask {

/**
* Ctor.
*
* @param delegate Delegate.
*/
protected Active(final Task delegate) {
super(delegate);
}

@Override
public String toString() {
return "active:-";
}
}

/**
* Closed task status.
*/
static class Closed extends StatusTask {


/**
* Invoice id.
*/
private final int invoiceId;

/**
* Ctor.
*
* @param delegate Delegate.
* @param invoiceId Invoice id.
*/
protected Closed(final Task delegate, final int invoiceId) {
super(delegate);
this.invoiceId = invoiceId;
}

@Override
public String toString() {
return "closed:"+this.invoiceId;
}
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/selfxdsd/selfweb/api/ContractsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public ResponseEntity<String> tasks(
if(contract == null) {
resp = ResponseEntity.noContent().build();
} else {
final Tasks tasks = contract.tasks();
final Tasks all = new AllTasks(contract);
resp = ResponseEntity.ok(
new JsonTasks(tasks).toString()
new JsonTasks(all).toString()
);
}
}
Expand Down Expand Up @@ -304,7 +304,6 @@ public ResponseEntity<Resource> invoicePdf(
)
);
resp = ResponseEntity.ok()
.contentLength(pdf.length())
.contentType(MediaType.APPLICATION_PDF)
.header(
"Content-Disposition",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/selfxdsd/selfweb/api/output/JsonTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public JsonTask(final Task task) {
super(
Json.createObjectBuilder()
.add("issueId", task.issueId())
.add("invoiceNumber", task.toString().split(":")[1])
.add("assignmentDate", String.valueOf(task.assignmentDate()))
.add("deadline", String.valueOf(task.deadline()))
.add("estimation", task.estimation())
.add("value", task.value().divide(BigDecimal.valueOf(100)))
.add("status", task.toString().split(":")[0])
.build()
);
}
Expand Down
32 changes: 30 additions & 2 deletions src/main/resources/public/js/getAndAddContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,29 @@ var projectContractsCount = -1;
)
$("#tasks").show();
$("#tasksTable").DataTable({
dom: 'Qlrtip',
searchBuilder: {
columns: [6],
conditions: {
string: {
"!=": null,
"!null": null,
"contains" : null,
"ends" : null,
"null" : null,
"starts" : null,
}
}
},
language: {
loadingRecords: '<img src="/images/loading.svg" height="100">'
loadingRecords: '<img src="/images/loading.svg" height="100">',
searchBuilder:{
add: "+",
title: {
0: 'Filters',
_: 'Filters (%d)'
},
},
},
ajax: {
url: "/api/projects/"
Expand Down Expand Up @@ -53,6 +74,9 @@ var projectContractsCount = -1;
return "<a href='" + issueLink + "' target='_blank'>#" + data + "</a>"
}
},
{
data: "invoiceNumber",
},
{
data: "assignmentDate",
render: (data) => data.split('T')[0]
Expand All @@ -68,8 +92,12 @@ var projectContractsCount = -1;
{
data: "value",
render: (data) => formatEuro(data)
},
{
data: "status",
orderable: false
}
]
],
})
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<link href="https://unpkg.com/@primer/css/dist/primer.css" rel="stylesheet" />
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/searchbuilder/1.0.1/css/searchBuilder.dataTables.min.css"/>

<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/searchbuilder/1.0.1/js/dataTables.searchBuilder.min.js"></script>
<script type="text/javascript" src="/webjars/bootstrap/js/bootstrap.bundle.min.js "></script>
<script type="text/javascript" src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<script type="text/javascript" src="/webjars/js-cookie/js.cookie.js"></script>
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/templates/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ <h4 class="m-0 font-weight-bold card-title">
</div>
</div>
<div class="row mt-4">
<div class="col-lg-6" id="tasks" style="display: none;">
<div class="col-lg-7" id="tasks" style="display: none;">
<div class="card shadow">
<div class="card-header py-3">
<h4 class="m-0 font-weight-bold card-title" id="tasksTitle">Tasks</h4>
Expand All @@ -325,11 +325,13 @@ <h4 class="m-0 font-weight-bold card-title" id="tasksTitle">Tasks</h4>
<table id="tasksTable" class="display">
<thead>
<tr>
<th>Issue</th>
<th>Issue ID</th>
<th>Invoice<br/>number</th>
<th>Assigned</th>
<th>Deadline</th>
<th>Estimation</th>
<th>Value</th>
<th>Status</th>
</tr>
</thead>
<tbody>
Expand All @@ -340,7 +342,7 @@ <h4 class="m-0 font-weight-bold card-title" id="tasksTitle">Tasks</h4>
</div>
</div>
</div>
<div class="col-lg-6" id="invoices" style="display: none;">
<div class="col-lg-5" id="invoices" style="display: none;">
<div class="card shadow">
<div class="card-header py-3">
<h4 class="m-0 font-weight-bold card-title" id="invoicesTitle">Invoices</h4>
Expand Down

0 comments on commit 34675b4

Please sign in to comment.