-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,288 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const TextField = ({ value, onChange, placeholder }) => { | ||
return ( | ||
<div className="form-group mb-0"> | ||
<div className="input-group"> | ||
<input type="text" className="form-control" placeholder={placeholder} | ||
value={ value } onChange={e => onChange(e.target.value)}></input> | ||
<span className="input-group-btn"> | ||
<button className="btn btn-default" onClick={() => onChange('')}> | ||
<span className="fa fa-times"></span> | ||
</button> | ||
</span> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
TextField.propTypes = { | ||
value: PropTypes.string.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
placeholder: PropTypes.string.isRequired | ||
} | ||
|
||
const Select = ({ value, options, onChange, placeholder }) => { | ||
return ( | ||
<div className="form-group mb-0"> | ||
<select className="form-control" value={value} onChange={e => onChange(e.target.value)}> | ||
<option value="">{placeholder}</option> | ||
{ | ||
options.map((option, index) => <option value={option} key={index}>{option}</option>) | ||
} | ||
</select> | ||
</div> | ||
) | ||
} | ||
|
||
Select.propTypes = { | ||
value: PropTypes.string, | ||
options: PropTypes.array.isRequired, | ||
onChange: PropTypes.func, | ||
placeholder: PropTypes.string | ||
} | ||
|
||
export { TextField, Select } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const Table = ({ | ||
cellFormatters, | ||
data, | ||
headerFormatters, | ||
initialRows = 25, | ||
rowsToLoad = 10, | ||
sortableColumns, | ||
/* order of elements in 'visibleColumns' corresponds to order of columns in table */ | ||
visibleColumns, | ||
}) => { | ||
const [displayedRows, setDisplayedRows] = useState(initialRows) | ||
const [sortColumn, setSortColumn] = useState(null) | ||
const [sortOrder, setSortOrder] = useState('asc') | ||
|
||
const loadMore = () => { | ||
setDisplayedRows(prev => prev + rowsToLoad) | ||
} | ||
|
||
const handleHeaderClick = column => { | ||
if (sortableColumns.includes(column)) { | ||
if (sortColumn === column) { | ||
setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc') | ||
} else { | ||
setSortColumn(column) | ||
setSortOrder('asc') | ||
} | ||
} | ||
} | ||
|
||
const sortedData = () => { | ||
if (sortColumn) { | ||
const sorted = [...data] | ||
|
||
sorted.sort((a, b) => { | ||
let valueA = a[sortColumn] | ||
let valueB = b[sortColumn] | ||
const sortRawContent = ( | ||
headerFormatters[sortColumn]?.sortRawContent ?? true | ||
) | ||
|
||
if (!sortRawContent) { | ||
valueA = formatCellContent(a, sortColumn, a[sortColumn]) | ||
valueB = formatCellContent(b, sortColumn, b[sortColumn]) | ||
} | ||
|
||
if (sortOrder === 'asc') { | ||
return valueA.localeCompare ? valueA.localeCompare(valueB) : valueA - valueB | ||
} else { | ||
return valueB.localeCompare ? valueB.localeCompare(valueA) : valueB - valueA | ||
} | ||
}) | ||
|
||
return sorted | ||
} | ||
return data | ||
} | ||
|
||
const renderHeaders = () => { | ||
return ( | ||
<thead className="thead-dark"> | ||
<tr> | ||
{visibleColumns.map(column => { | ||
const headerFormatter = headerFormatters[column] | ||
const columnHeaderContent = headerFormatter && headerFormatter.render ? headerFormatter.render(column) : column | ||
|
||
return ( | ||
<th key={column} onClick={() => handleHeaderClick(column)}> | ||
{columnHeaderContent} | ||
{sortColumn === column && ( | ||
<span className="sort-icon"> | ||
{sortOrder === 'asc' ? <i className="fa fa-sort-asc" /> : <i className="fa fa-sort-desc" />} | ||
</span> | ||
)} | ||
</th> | ||
) | ||
})} | ||
</tr> | ||
</thead> | ||
) | ||
} | ||
|
||
const formatCellContent = (row, column, content) => { | ||
if (cellFormatters && cellFormatters[column] && typeof cellFormatters[column] === 'function') { | ||
return cellFormatters[column](content, row) | ||
} | ||
return content | ||
} | ||
|
||
const renderRows = () => { | ||
const sortedRows = sortedData().slice(0, displayedRows) | ||
|
||
return ( | ||
<tbody> | ||
{sortedRows.map((row, index) => ( | ||
<tr key={index}> | ||
{visibleColumns.map(column => ( | ||
<td key={column}>{formatCellContent(row, column, row[column])}</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="table-container"> | ||
<table className="table table-borderless"> | ||
{renderHeaders()} | ||
{renderRows()} | ||
</table> | ||
{displayedRows < data.length && ( | ||
<button onClick={loadMore} className="load-more-btn"> | ||
{gettext('Load More')} | ||
</button> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
Table.propTypes = { | ||
cellFormatters: PropTypes.object, | ||
data: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
headerFormatters: PropTypes.object, | ||
initialRows: PropTypes.number, | ||
rowsToLoad: PropTypes.number, | ||
sortableColumns: PropTypes.arrayOf(PropTypes.string), | ||
visibleColumns: PropTypes.arrayOf(PropTypes.string), | ||
} | ||
|
||
export default Table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// take the language from the <head> of the django template | ||
export default document.querySelector('meta[name="language"]').content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// take the site_id from the <head> of the django template | ||
export default Number(document.querySelector('meta[name="site_id"]').content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// take the staticurl from the <head> of the django template | ||
export default document.querySelector('meta[name="staticurl"]').content.replace(/\/+$/, '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends 'core/base.html' %} | ||
|
||
{% block content %} | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="page col-md-12"> | ||
{% block page %}{% endblock %} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { UPDATE_CONFIG } from './types' | ||
|
||
export function updateConfig(path, value) { | ||
return {type: UPDATE_CONFIG, path, value} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
import ProjectsApi from '../api/ProjectsApi' | ||
import { FETCH_PROJECTS_ERROR, FETCH_PROJECTS_INIT, FETCH_PROJECTS_SUCCESS } | ||
from './types' | ||
|
||
// export function fetchAllProjects() { | ||
// return function(dispatch) { | ||
// dispatch(fetchProjectsInit()) | ||
// const action = (dispatch) => ProjectsApi.fetchProjects(true) | ||
// .then(projects => { | ||
// dispatch(fetchProjectsSuccess({ projects }))}) | ||
|
||
// return dispatch(action) | ||
// .catch(error => dispatch(fetchProjectsError(error))) | ||
// } | ||
// } | ||
|
||
export function fetchAllProjects() { | ||
return function(dispatch) { | ||
dispatch(fetchProjectsInit()) | ||
const action = (dispatch) => | ||
ProjectsApi.fetchProjects(true) | ||
.then(projects => { | ||
const fetchProgressPromises = projects.map(project => | ||
ProjectsApi.fetchProgress(project.id) | ||
.then(progress => ({ ...project, progress: {count: progress.count, total: progress.total} })) | ||
) | ||
|
||
return Promise.all(fetchProgressPromises) | ||
.then(updatedProjects => { | ||
dispatch(fetchProjectsSuccess({ projects: updatedProjects })) | ||
}) | ||
}) | ||
|
||
return dispatch(action) | ||
.catch(error => dispatch(fetchProjectsError(error))) | ||
} | ||
} | ||
|
||
export function fetchProjectsInit() { | ||
return {type: FETCH_PROJECTS_INIT} | ||
} | ||
|
||
export function fetchProjectsSuccess(projects) { | ||
return {type: FETCH_PROJECTS_SUCCESS, projects} | ||
} | ||
|
||
export function fetchProjectsError(error) { | ||
return {type: FETCH_PROJECTS_ERROR, error} | ||
} | ||
|
||
// export function updateConfig(path, value) { | ||
// return {type: 'projects/updateConfig', path, value} | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const FETCH_PROJECTS_SUCCESS = 'projects/fetchProjectsSuccess' | ||
export const FETCH_PROJECTS_ERROR = 'projects/fetchProjectsError' | ||
export const FETCH_PROJECTS_INIT = 'projects/fetchProjectsInit' | ||
export const FETCH_CURRENT_USER_INIT = 'currentUser/fetchCurrentUserInit' | ||
export const FETCH_CURRENT_USER_SUCCESS = 'currentUser/fetchCurrentUserSuccess' | ||
export const FETCH_CURRENT_USER_ERROR = 'currentUser/fetchCurrentUserError' | ||
export const UPDATE_CONFIG = 'config/updateConfig' |
Oops, something went wrong.