-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDC #2 - Adding ability to create projects/users
- Loading branch information
1 parent
39c3c41
commit eb11491
Showing
50 changed files
with
1,586 additions
and
1,207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Api::ProjectsController < Api::BaseController | ||
search_attributes :name | ||
end |
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 @@ | ||
class Project < ApplicationRecord | ||
# Relationships | ||
has_many :user_projects, dependent: :destroy | ||
|
||
# Resourceable parameters | ||
allow_params :name, :description | ||
end |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
class User < ApplicationRecord | ||
# JWT | ||
has_secure_password | ||
# Relationships | ||
has_many :user_projects, dependent: :destroy | ||
|
||
# Resourceable parameters | ||
allow_params :name, :email, :password, :password_confirmation | ||
allow_params :name, :email, :password, :password_confirmation, :admin | ||
|
||
# JWT | ||
has_secure_password | ||
end |
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,11 @@ | ||
class UserProject < ApplicationRecord | ||
# Relationships | ||
belongs_to :user | ||
belongs_to :project | ||
|
||
# Resourceable parameters | ||
allow_params :user_id, :project_id, :role | ||
|
||
# Validations | ||
validates_presence_of :role | ||
end |
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,4 @@ | ||
class ProjectsSerializer < BaseSerializer | ||
index_attributes :id, :name, :description | ||
show_attributes :id, :name, :description | ||
end |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,69 @@ | ||
// @flow | ||
|
||
import { Breadcrumbs } from '@performant-software/semantic-components'; | ||
import React, { useEffect, useMemo, useRef, useState, type AbstractComponent } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Link, Outlet, useLocation, useParams } from 'react-router-dom'; | ||
import { Container } from 'semantic-ui-react'; | ||
import _ from 'underscore'; | ||
import BreadcrumbsService, { Services } from '../services/Breadcrumbs'; | ||
import Sidebar from './Sidebar'; | ||
import styles from './Layout.module.css'; | ||
|
||
const Layout: AbstractComponent<any> = () => { | ||
const [menuWidth, setMenuWidth] = useState(0); | ||
const menuRef = useRef(); | ||
|
||
const { pathname } = useLocation(); | ||
const params = useParams(); | ||
|
||
const { t } = useTranslation(); | ||
const defaultLabel = { new: t('Layout.labels.new') }; | ||
|
||
/** | ||
* Builds the map of URL key to label. | ||
*/ | ||
const labels = useMemo(() => _.reduce( | ||
_.keys(Services), | ||
(memo, key) => _.extend(memo, { [key] : t(`Layout.labels.${key}`) }), | ||
defaultLabel | ||
), [defaultLabel, t]); | ||
|
||
/** | ||
* Sets the sidebar menu width when the component is mounted. | ||
*/ | ||
useEffect(() => { | ||
const { current: instance } = menuRef; | ||
|
||
if (instance) { | ||
setMenuWidth(instance.offsetWidth); | ||
} | ||
}, [menuRef.current]); | ||
|
||
return ( | ||
<Container | ||
className={styles.layout} | ||
fluid | ||
> | ||
<Sidebar | ||
context={menuRef} | ||
/> | ||
<div | ||
className={styles.content} | ||
style={{ | ||
marginLeft: `${menuWidth}px` | ||
}} | ||
> | ||
<Breadcrumbs | ||
as={Link} | ||
labels={labels} | ||
onLoad={(id, name) => BreadcrumbsService.onLoad(name, id, params)} | ||
pathname={pathname} | ||
/> | ||
<Outlet /> | ||
</div> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Layout; |
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,4 @@ | ||
.layout > .content { | ||
height: 100vh; | ||
padding: 1em 2em 1em 2em; | ||
} |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
// @flow | ||
|
||
import React, { type ComponentType, type Node } from 'react'; | ||
import { | ||
Link, | ||
useMatch, | ||
useResolvedPath | ||
} from 'react-router-dom'; | ||
import { Menu } from 'semantic-ui-react'; | ||
import _ from 'underscore'; | ||
|
||
type Props = { | ||
children?: Node | (active: boolean) => Node, | ||
parent?: boolean, | ||
to: string | ||
}; | ||
|
||
const MenuLink: ComponentType<any> = (props: Props) => { | ||
const url = `${props.to}${props.parent ? '/*' : ''}`; | ||
const { pathname } = useResolvedPath(url); | ||
const active = useMatch({ path: pathname, end: true }); | ||
|
||
return ( | ||
<Menu.Item | ||
{..._.omit(props, 'children')} | ||
active={active} | ||
as={Link} | ||
> | ||
{ props.children } | ||
</Menu.Item> | ||
); | ||
}; | ||
|
||
export default MenuLink; |
Oops, something went wrong.