Skip to content

Commit 1520276

Browse files
authored
Merge pull request #1243 from rdmorganiser/project-page
New project detail page - sidebar, form, helper components, css
2 parents 0bea863 + d54d722 commit 1520276

36 files changed

+1048
-54
lines changed

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@codemirror/lang-javascript": "^6.2.2",
1717
"@uiw/react-codemirror": "^4.23.0",
1818
"bootstrap": "^5.3.3",
19+
"bootstrap-icons": "^1.11.3",
1920
"bootstrap-sass": "^3.4.1",
2021
"classnames": "^2.5.1",
2122
"date-fns": "^3.6.0",

rdmo/core/assets/js/actions/actionTypes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export const FETCH_TEMPLATES_SUCCESS = 'FETCH_TEMPLATES_SUCCESS'
1515
export const FETCH_CURRENT_USER_ERROR = 'FETCH_CURRENT_USER_ERROR'
1616
export const FETCH_CURRENT_USER_INIT = 'FETCH_CURRENT_USER_INIT'
1717
export const FETCH_CURRENT_USER_SUCCESS = 'FETCH_CURRENT_USER_SUCCESS'
18+
19+
export const FETCH_CATALOGS_ERROR = 'FETCH_CATALOGS_ERROR'
20+
export const FETCH_CATALOGS_INIT = 'FETCH_CATALOGS_INIT'
21+
export const FETCH_CATALOGS_SUCCESS = 'FETCH_CATALOGS_SUCCESS'

rdmo/core/assets/js/components/Select.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,35 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import ReactSelect from 'react-select'
44

5-
const Select = ({ options, onChange, placeholder, value }) => {
5+
const Select = ({ options, onChange, value, ...props }) => {
66
const selectedOption = options.find(option => option.value === value) || null
7+
78
const handleChange = (selected) => {
89
onChange(selected ? selected.value : null)
910
}
1011

1112
return (
12-
<div className="form-group mb-0">
13-
<ReactSelect
14-
className="react-select"
15-
classNamePrefix="react-select"
16-
options={options}
17-
onChange={handleChange}
18-
value={selectedOption}
19-
isClearable
20-
placeholder={placeholder}
21-
/>
22-
</div>
13+
<ReactSelect
14+
className="react-select"
15+
classNamePrefix="react-select"
16+
options={options}
17+
onChange={handleChange}
18+
value={selectedOption}
19+
isClearable
20+
{...props}
21+
/>
2322
)
2423
}
2524

2625
Select.propTypes = {
27-
value: PropTypes.string,
26+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2827
options: PropTypes.arrayOf(
2928
PropTypes.shape({
30-
value: PropTypes.string.isRequired,
29+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
3130
label: PropTypes.string.isRequired
3231
})
3332
).isRequired,
3433
onChange: PropTypes.func,
35-
placeholder: PropTypes.string
3634
}
3735

3836
export default Select
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FETCH_CATALOGS_ERROR, FETCH_CATALOGS_INIT, FETCH_CATALOGS_SUCCESS } from '../actions/actionTypes'
2+
3+
const initialState = {}
4+
5+
export default function settingsReducer(state = initialState, action) {
6+
switch(action.type) {
7+
case FETCH_CATALOGS_INIT:
8+
return {...state, ...action.catalogs}
9+
case FETCH_CATALOGS_SUCCESS:
10+
return {...state, ...action.catalogs}
11+
case FETCH_CATALOGS_ERROR:
12+
return {...state, errors: action.error.errors}
13+
default:
14+
return state
15+
}
16+
}

rdmo/core/assets/scss/_bs53/base.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import '~bootstrap/scss/bootstrap';
2+
@import 'fonts';
23

34
.react-select .form-select {
45
padding: 0;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1, h2, h3, h4, h5, h6 {
2+
color: green;
3+
}

rdmo/core/templates/core/bs53/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% load static compress core_tags %}<!DOCTYPE html>
22
<html>
33
<head>
4-
{% include 'core/base_head.html' %}
4+
{% include 'core/bs53/base_head.html' %}
55

66
{% block css %}{% endblock %}
77
{% block js %}{% endblock %}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% load static %}
2+
{% load i18n %}
3+
{% get_current_language as LANGUAGE_CODE %}
4+
5+
<title>{{ request.site.name }}</title>
6+
7+
<meta charset="UTF-8" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
9+
10+
<meta property="og:title" content="{{ request.site.name }}" />
11+
<meta property="og:url" content="{{ request.site.domain }}" />
12+
13+
<meta name='baseurl' content="{% url 'home' %}" />
14+
<meta name='staticurl' content="{% static '' %}" />
15+
<meta name='site_id' content="{{ settings.SITE_ID }}" />
16+
<meta name='language' content="{{ LANGUAGE_CODE }}">
17+
18+
<link rel="shortcut icon" href="{% static 'core/img/favicon.png' %}" type="image/png" />
19+
20+
{% block vendor %}
21+
<!-- Bootstrap CSS & JS -->
22+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
23+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" defer></script>
24+
{% endblock %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import BaseApi from 'rdmo/core/assets/js/api/BaseApi'
2+
3+
class CatalogsApi extends BaseApi {
4+
static fetchCatalogs() {
5+
return fetch('/api/v1/projects/catalogs/').then(response => {
6+
if (response.ok) {
7+
return response.json()
8+
} else {
9+
throw new Error(response.statusText)
10+
}
11+
})
12+
}
13+
}
14+
15+
export default CatalogsApi
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// project roles
2+
export const ROLE_LABELS = {
3+
author: gettext('Author'),
4+
guest: gettext('Guest'),
5+
manager: gettext('Manager'),
6+
owner: gettext('Owner')
7+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ROLE_LABELS } from './constants'
2+
3+
export const getUserRoles = (project, currentUserId, arraysToSearch) => {
4+
if (!arraysToSearch || !arraysToSearch.length) {
5+
arraysToSearch = ['authors', 'guests', 'managers', 'owners']
6+
}
7+
8+
const roleDefinitions = {
9+
authors: { roleLabel: ROLE_LABELS.author, roleBoolean: 'isProjectAuthor' },
10+
guests: { roleLabel: ROLE_LABELS.guest, roleBoolean: 'isProjectGuest' },
11+
managers: { roleLabel: ROLE_LABELS.manager, roleBoolean: 'isProjectManager' },
12+
owners: { roleLabel: ROLE_LABELS.owner, roleBoolean: 'isProjectOwner' }
13+
}
14+
15+
let rolesFound = []
16+
let roleBooleans = {
17+
isProjectAuthor: false,
18+
isProjectGuest: false,
19+
isProjectManager: false,
20+
isProjectOwner: false
21+
}
22+
23+
arraysToSearch.forEach(arrayName => {
24+
if (project[arrayName].some(item => item.id === currentUserId)) {
25+
const { roleLabel, roleBoolean } = roleDefinitions[arrayName]
26+
rolesFound.push(roleLabel)
27+
roleBooleans[roleBoolean] = true
28+
}
29+
})
30+
31+
return {
32+
rolesString: rolesFound.length > 0 ? rolesFound.join(', ') : null,
33+
...roleBooleans
34+
}
35+
}
36+
37+
export default getUserRoles
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './constants'
2+
export { default as getUserRoles } from './getUserRoles'
3+
export { default as userIsManager } from './userIsManager'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { siteId } from 'rdmo/core/assets/js/utils/meta'
2+
3+
const userIsManager = (currentUser) => {
4+
if (currentUser.is_superuser ||
5+
(currentUser.role && currentUser.role.manager && currentUser.role.manager.some(manager => manager.id === siteId))) {
6+
return true
7+
}
8+
return false
9+
}
10+
11+
export default userIsManager
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export const FETCH_PROJECT_INIT = 'FETCH_PROJECT_INIT'
22
export const FETCH_PROJECT_SUCCESS = 'FETCH_PROJECT_SUCCESS'
33
export const FETCH_PROJECT_ERROR = 'FETCH_PROJECT_ERROR'
4+
export const UPDATE_PROJECT_INIT = 'UPDATE_PROJECT_INIT'
5+
export const UPDATE_PROJECT_SUCCESS = 'UPDATE_PROJECT_SUCCESS'
6+
export const UPDATE_PROJECT_ERROR = 'UPDATE_PROJECT_ERROR'
7+
export const DELETE_PROJECT_INIT = 'DELETE_PROJECT_INIT'
8+
export const DELETE_PROJECT_SUCCESS = 'DELETE_PROJECT_SUCCESS'
9+
export const DELETE_PROJECT_ERROR = 'DELETE_PROJECT_ERROR'

0 commit comments

Comments
 (0)