Skip to content

Commit

Permalink
Merge pull request #553 from ECLK/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MrClemRkz authored Jul 14, 2020
2 parents 1d18307 + e0eab7a commit b3c7bbf
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 34 deletions.
2 changes: 1 addition & 1 deletion backend/src/incidents/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class IncidentSerializer(serializers.ModelSerializer):

lastAssignment = serializers.SerializerMethodField(method_name="get_last_assignment")

severity = serializers.IntegerField(initial=0, allow_null=True)
severity = serializers.IntegerField(initial=1, allow_null=True)

# refId = serializers.CharField(required=False)
# election = serializers.CharField(required=False)
Expand Down
22 changes: 13 additions & 9 deletions backend/src/incidents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get(self, request, format=None):
# print("assigneee", find_incident_assignee(_user))
election_code = settings.ELECTION

incidents = Incident.objects.all().filter(election=election_code).order_by('created_date').reverse()
incidents = Incident.objects.filter(election=election_code).order_by('created_date').reverse()
user = request.user

# for external entities, they can only view related incidents
Expand All @@ -111,6 +111,18 @@ def get(self, request, format=None):
Q(refId__icontains=param_query) | Q(title__icontains=param_query) |
Q(description__icontains=param_query))

# for archive page
param_archived_only = self.request.query_params.get('show_archived_only', None)
if param_archived_only is not None and param_archived_only == "true":
incidents = incidents.filter(Q(current_status=StatusType.CLOSED.name) | Q(current_status=StatusType.INVALIDATED.name))

# by default exclude archive status: CLOSED and INVALIDATED
# if show_archived is true; then shows all
param_archived = self.request.query_params.get('show_archived', None)
if param_archived is None and not (param_archived == "false" or param_archived_only == "true"):
# this conditions is always true when no value is given for 'show_archived'
incidents = incidents.exclude(Q(current_status=StatusType.CLOSED.name) | Q(current_status=StatusType.INVALIDATED.name))

# filter by title
param_title = self.request.query_params.get('title', None)
if param_title is not None:
Expand Down Expand Up @@ -165,14 +177,6 @@ def get(self, request, format=None):
except:
raise IncidentException("Severity level must be a number")

param_closed = self.request.query_params.get('show_closed', None)

if param_closed is not None and param_closed == "true":
# by default CLOSED incidents are not shown
incidents = incidents.filter(current_status=StatusType.CLOSED.name)
else:
incidents = incidents.exclude(current_status=StatusType.CLOSED.name)

param_institution = self.request.query_params.get('institution', None)
if param_institution is not None:
incidents = incidents.filter(institution=param_institution)
Expand Down
6 changes: 3 additions & 3 deletions backend/src/reporting/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_daily_incident_detail_list():
# get last assignment comment
incident_dict["reportedParty"] = "-"
incident_dict["progress"] = "-"
comment = get_incident_assignment_comment(incident.refId)
comment = get_incident_assignment_comment(incident.id)
if (comment):
incident_dict["reportedParty"] = comment[0]
incident_dict["progress"] = comment[1]
Expand All @@ -164,8 +164,8 @@ def get_daily_incident_detail_list():

return file_dict

def get_incident_assignment_comment(refId):
incident = Incident.objects.get(refId=refId)
def get_incident_assignment_comment(id):
incident = Incident.objects.get(id=id)
comment = IncidentComment.objects.filter(Q(incident=incident) & Q(body__contains="---")).order_by("-created_date").first()

# check if there's any comment for the incident
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/api/incident.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ export const getIncidents = async (filters, page = 1) => {
query += "&export=" + filters.export;
}

if (filters.show_closed) {
query += "&show_closed=" + filters.show_closed;
if (filters.show_archived_only) {
query += "&show_archived_only=" + filters.show_archived_only;
}

if (filters.show_archived) {
query += "&show_archived=" + filters.show_archived
}

if (filters.title) {
Expand Down
36 changes: 34 additions & 2 deletions frontend/src/home/components/Home.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, useEffect, useState } from "react";
import { Link } from 'react-router-dom';
import { withRouter } from "react-router";

Expand All @@ -7,6 +7,8 @@ import { Card, Grid, CardContent, CardHeader } from '@material-ui/core';
import ManagedIncidentList from './ManagedIncidentList';
import { useSelector } from 'react-redux';
import { userCan, USER_ACTIONS } from '../../user/userUtils';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Checkbox from '@material-ui/core/Checkbox';

const drawerWidth = 240;
const styles = theme => ({
Expand All @@ -19,6 +21,19 @@ const styles = theme => ({
});
const Home = ({classes, ...props}) =>{
const user = useSelector(state => state.shared.signedInUser.data);
const [state, setState] = useState({checked: false});


const handleChange = (event) => {
setState({...state, checked: event.target.checked});
}
var obj = {}

if(state.checked == true){
obj = { show_archived: "true", assignee: "me" }
}else{
obj = { assignee: "me" }
}

return (
<Grid container>
Expand All @@ -29,9 +44,26 @@ const Home = ({classes, ...props}) =>{
<CardHeader
title="Incidents Assigned to You"
/>
<Grid container
direction="row"
justify="flex-end"
alignItems="baseline"
>
<Grid item
style={{marginRight:'2rem'}}
>
<FormControlLabel
value="start"
control={<Checkbox checked={state.checked} onChange={handleChange} color="primary" />}
label="Show Archived"
labelPlacement="start"
/>
</Grid>
</Grid>

<CardContent>
<ManagedIncidentList
filters={ { assignee: "me" } }
filters={ obj }
/>
</CardContent>
</Card>
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/home/components/ManagedIncidentList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { withRouter } from 'react-router';
import IncidentList from '../../incident/components/IncidentList';
import { getIncidents } from '../../api/incident';
Expand All @@ -17,8 +17,10 @@ export function ManagedIncidentList({ filters, history }){

useEffect(() => {
callAPI();
}, []);
}, [filters]);



return (
<IncidentList
incidents={incidents}
Expand Down
25 changes: 16 additions & 9 deletions frontend/src/incident/components/IncidentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ const styles = theme => ({
},
cursor: "pointer"
},
row2: {
backgroundColor: "#EBEBE4",
cursor: "pointer",
},
cell2: {
color: "#7b7a7a",
},
root: {
display: "flex",
flexWrap: "wrap",
Expand Down Expand Up @@ -111,32 +118,32 @@ function IncidentList({ classes, incidents, pageNumber, count, handleRowClick, h
<TableRow
onClick={() => handleRowClick(row.id)}
hover
className={classes.row}
className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.row2 : classes.row}
key={row.id}
>
<CustomTableCell scope="center">
<p>{row.refId}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""}>{row.refId}</p>
</CustomTableCell>
<CustomTableCell scope="center">
<p>{row.title}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.title}</p>
</CustomTableCell>
<CustomTableCell>
<p className="description">{row.description}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""}>{row.description}</p>
</CustomTableCell>
<CustomTableCell align="center">
<p>{row.currentStatus}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.currentStatus}</p>
</CustomTableCell>
<CustomTableCell align="center">
<p>{row.severity}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.severity}</p>
</CustomTableCell>
<CustomTableCell align="center">
<p>{row.response_time} h</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.response_time} h</p>
</CustomTableCell>
<CustomTableCell align="center">
<p>{row.category}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.category}</p>
</CustomTableCell>
<CustomTableCell align="center">
<p>{row.subCategory}</p>
<p className={(row.currentStatus == "CLOSED" || row.currentStatus == "INVALIDATED" )? classes.cell2 : ""} >{row.subCategory}</p>
</CustomTableCell>
</TableRow>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function ArchiveIncidentListView({ classes, ...props }) {
if(!filters){
filters = {};
}
filters["show_closed"] = true;
filters["show_archived_only"] = true;
setFilters(filters);
dispatch(loadAllIncidents(filters, page))
}
Expand All @@ -54,7 +54,7 @@ function ArchiveIncidentListView({ classes, ...props }) {
if (exportType === "csv") {
const url = window.URL.createObjectURL(new Blob([response]));
const link = document.createElement('a');
link.href = url;
link.href = url;
link.setAttribute('download', 'incidents.' + exportType);
document.body.appendChild(link);
link.click();
Expand All @@ -70,12 +70,12 @@ function ArchiveIncidentListView({ classes, ...props }) {

}
}

return (
<Paper className={classes.root}>
<SearchForm
categories={categories}
handleSearchClick={handleSearchClick}
<SearchForm
categories={categories}
handleSearchClick={handleSearchClick}
showClosed={false}
{...props} />
<Grid container direction={"row"} className={classes.exportContainer}>
Expand Down

0 comments on commit b3c7bbf

Please sign in to comment.