Commit 3278b46d authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '104-ssr-admin-repository-f' into 'master'

Resolve "SSR: admin/repository/f/"

Closes #104

See merge request genesys-pgr/genesys-ui!99
parents e4267a5d 24efb6eb
export default function fetchComponentData(dispatch, branch, search) {
export default function fetchComponentData(dispatch, branch, search, state = null) {
const promisesWithProps = [];
branch.map(({ route, match }) => {
......@@ -8,9 +8,12 @@ export default function fetchComponentData(dispatch, branch, search) {
return;
}
const ownProps = { route, match };
// console.log('SSR need with arguments (state, ownProps, search)=', '..snip..'); // , ownProps, search);
// Provide params to static needs
component.needs.filter((need) => need({ search, params: match.params })).map((need) => {
return dispatch(need({ search, params: match.params }));
component.needs.filter((need) => need({ state, ownProps, search, params: match.params })).map((need) => {
return dispatch(need({ state, ownProps, search, params: match.params }));
})
// a nice array of Promises
.forEach((promise) => promisesWithProps.push(promise));
......
......@@ -112,7 +112,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
console.log(`Rendering ${pathWithoutLang} for ${pathname}`);
const branch = matchRoutes(routes, pathWithoutLang);
fetchComponentData(store.dispatch, branch, search)
fetchComponentData(store.dispatch, branch, search, store.getState())
.catch((err) => {
console.log('Error fetching component data', err);
res.status(500).end(err.message);
......
......@@ -6,6 +6,7 @@ import { Permissions, IUserPermissions } from 'model/acl/ACL';
*/
class RepositoryFile implements IUserPermissions {
public _permissions: Permissions;
public _class: string;
public static clazz: string = 'org.genesys.filerepository.model.RepositoryFile';
public accessRights: string;
......
......@@ -4,6 +4,8 @@ import RepositoryFile from 'model/repository/RepositoryFile';
* Defined in Swagger as '#/definitions/RepositoryImage'
*/
class RepositoryImage extends RepositoryFile {
public static clazz: string = 'org.genesys.filerepository.model.RepositoryImage';
public format: string;
public height: number;
public orientation: string;
......
......@@ -51,12 +51,12 @@ const styles = (theme) => ({
class RepositoryBrowser extends React.Component<IRepositoryBrowserProps, any> {
protected static needs = [
({ root, path }) => getFolder(root + path),
({ ownProps }) => getFolder(normalize((ownProps.route.root || '/') + (ownProps.match.params.path || '/')).replace(/^(.+)\/$/, '$1')),
];
public componentWillMount() {
const { folder, folderPath, getFolder } = this.props;
// console.log(`RepositoryBrowser.componentWillMount...`, normalize(root + path));
// console.log(`RepositoryBrowser.cwm...`, folderPath);
if (!folder || (folder.folder && folder.folder.path !== folderPath)) {
// console.log(`Loading folder root=${root} path=${path}`);
......
......@@ -5,14 +5,15 @@ import { translate } from 'react-i18next';
import RepositoryFile from 'model/repository/RepositoryFile';
// UI
import Card, {CardHeader, CardContent} from 'ui/common/Card';
import {Properties, PropertiesItem} from 'ui/common/Properties';
import Card, { CardHeader, CardContent } from 'ui/common/Card';
import { Properties, PropertiesItem } from 'ui/common/Properties';
import ActionButton from 'ui/common/buttons/ActionButton';
import Permissions from 'ui/common/permission/Permissions';
import PrettyDate from 'ui/common/time/PrettyDate';
import DownloadIcon from '@material-ui/icons/GetApp';
import withStyles from '@material-ui/core/styles/withStyles';
import Grid from '@material-ui/core/Grid';
import RepositoryImage from 'model/repository/RepositoryImage';
/*tslint:disable*/
const style = (theme) => ({
......@@ -80,6 +81,16 @@ const FileCard = ({file, classes, compact = false, edit = false, deleteFile, edi
return null;
}
// console.log('File', className, file);
// We have different types of Repository items, need to resolve to proper server class name
let className: string = RepositoryFile.clazz;
switch (file._class) {
case 'RepositoryImage':
className = RepositoryImage.clazz;
break;
}
return compact ? (
<Grid item xs={ 12 }>
<Card className={ classes.root }>
......@@ -100,7 +111,7 @@ const FileCard = ({file, classes, compact = false, edit = false, deleteFile, edi
<div className={ classes.actions }>
<span><ActionButton action={ () => editFile(file.uuid) } title={ t('common:action.edit') } /></span>
<span><ActionButton action={ () => deleteFile(file.uuid) } title={ t('common:action.delete') } /></span>
{ file && file._permissions.manage && <Permissions clazz={ RepositoryFile.clazz } id={ file.id } /> }
{ file && file._permissions.manage && <Permissions clazz={ className } id={ file.id } /> }
</div>
}
/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment