Skip to content

Commit

Permalink
feat: create menu entries with user favorite folders (axelor#817)
Browse files Browse the repository at this point in the history
* RM#86495
  • Loading branch information
vhu-axelor authored and lme-axelor committed Jan 13, 2025
1 parent 5393f83 commit 060b464
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import {AuthorFilter, DirectoryCard} from '../../atoms';
import {DocumentActionCard} from '../../molecules';
import {File} from '../../../types';

const DocumentList = () => {
interface DocumentListProps {
defaultParent?: any;
}

const DocumentList = ({defaultParent}: DocumentListProps) => {
const I18n = useTranslator();
const Colors = useThemeColor();

Expand Down Expand Up @@ -118,6 +122,7 @@ const DocumentList = () => {
/>
}
displayBreadcrumb
defaultParent={defaultParent}
/>
</Screen>
);
Expand Down
1 change: 1 addition & 0 deletions packages/apps/dms/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Dms_Details": "Details",
"Dms_Rename": "Rename",
"Dms_Delete": "Delete",
"Dms_MyFavoriteDocuments": "My favorite documents",
"Dms_SliceAction_SearchDocument": "search document",
"Dms_SliceAction_SearchDirectory": "search directory"
}
1 change: 1 addition & 0 deletions packages/apps/dms/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Dms_Details": "Détails",
"Dms_Rename": "Renommer",
"Dms_Delete": "Supprimer",
"Dms_MyFavoriteDocuments": "Mes fichiers favoris",
"Dms_SliceAction_SearchDocument": "recherche sur les documents",
"Dms_SliceAction_SearchDirectory": "recherche sur les dossiers"
}
20 changes: 19 additions & 1 deletion packages/apps/dms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {Module} from '@axelor/aos-mobile-core';
import {getLoggedUser, Module, modulesProvider} from '@axelor/aos-mobile-core';
import enTranslations from './i18n/en.json';
import frTranslations from './i18n/fr.json';
import DmsScreens from './screens';
import * as dmsReducers from './features';
import {dms_modelAPI, dms_searchFields, dms_sortFields} from './models';
import {createMenusScreen} from './utils';

export const DmsModule: Module = {
name: 'app-dms',
Expand Down Expand Up @@ -50,10 +51,27 @@ export const DmsModule: Module = {
searchFields: {...dms_searchFields},
sortFields: {...dms_sortFields},
},
moduleRegister: async (userId: number) => {
const user = await getLoggedUser(userId)
.then(res => res?.data?.data?.[0])
.catch(() => ({}));

const {menus, screens} = createMenusScreen({
favouriteFolderSet: user?.favouriteFolderSet,
favouriteFileSet: user?.favouriteFileSet,
});

modulesProvider.registerModule({
name: 'app-dms-favorites',
menus,
screens,
});
},
};

export * from './api';
export * from './components';
export * from './features/asyncFunctions-index';
export * from './screens';
export * from './types';
export * from './utils';
6 changes: 6 additions & 0 deletions packages/apps/dms/src/models/objectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export const dms_modelAPI: ObjectFields = {
createdOn: schemaContructor.string(),
metaFile: schemaContructor.subObject('fileName'),
}),
auth_user: schemaContructor.object({
favouriteFolderSet: schemaContructor
.array()
.of(schemaContructor.subObject()),
favouriteFileSet: schemaContructor.array().of(schemaContructor.subObject()),
}),
};
4 changes: 2 additions & 2 deletions packages/apps/dms/src/screens/AllDocumentsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import React from 'react';
import {DocumentList} from '../components';

const AllDocumentsScreen = ({}) => {
return <DocumentList />;
const AllDocumentsScreen = ({defaultParent}) => {
return <DocumentList defaultParent={defaultParent} />;
};

export default AllDocumentsScreen;
30 changes: 30 additions & 0 deletions packages/apps/dms/src/screens/MyFavoriteDocumentsScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import {Screen, Text} from '@axelor/aos-mobile-ui';

const MyFavoriteDocumentsScreen = ({}) => {
return (
<Screen removeSpaceOnTop={true}>
<Text>MyFavoriteDocumentsScreen</Text>
</Screen>
);
};

export default MyFavoriteDocumentsScreen;
9 changes: 9 additions & 0 deletions packages/apps/dms/src/screens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import AllDocumentsScreen from './AllDocumentsScreen';
import MyFavoriteDocumentsScreen from './MyFavoriteDocumentsScreen';

export default {
AllDocumentsScreen: {
Expand All @@ -27,6 +28,14 @@ export default {
},
isUsableOnShortcut: true,
},
FavoriteDocuments: {
title: 'Dms_MyFavoriteDocuments',
component: MyFavoriteDocumentsScreen,
options: {
shadedHeader: false,
},
},
};

export {AllDocumentsScreen};
export {MyFavoriteDocumentsScreen};
19 changes: 19 additions & 0 deletions packages/apps/dms/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export * from './moduleHelper';
82 changes: 82 additions & 0 deletions packages/apps/dms/src/utils/moduleHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {Menu, Screen} from '@axelor/aos-mobile-core';
import {AllDocumentsScreen} from '../screens';

const createAllDocumentsScreenComponent = (defaultParent: any) => {
return props => AllDocumentsScreen({...props, defaultParent});
};

type DMSFile = {
id: number;
fileName: string;
};

type Menus = {
[menuKey: string]: Menu;
};

type Screens = {
[screenKey: string]: Screen;
};

export const createMenusScreen = ({
favouriteFolderSet,
favouriteFileSet,
}: {
favouriteFolderSet: DMSFile[];
favouriteFileSet: DMSFile[];
}): {menus: Menus; screens: Screens} => {
let menus: Menus = {};
let screens: Screens = {};

if (Array.isArray(favouriteFileSet) && favouriteFileSet.length > 0) {
menus = {
dms_menu_favoriteDocuments: {
title: 'Dms_MyFavoriteDocuments',
icon: 'folder-check',
parent: 'app-dms',
screen: 'FavoriteDocuments',
},
};
}

if (Array.isArray(favouriteFolderSet) && favouriteFolderSet.length > 0) {
favouriteFolderSet.forEach(folder => {
const screenKey = `DocumentsScreen_${folder.id}`;
screens[screenKey] = {
title: 'Dms_AllDocuments',
component: createAllDocumentsScreenComponent(folder),
options: {
shadedHeader: false,
},
};

const menuKey = `dms_menu_documents${folder.id}`;
menus[menuKey] = {
title: folder.fileName,
icon: 'folder',
parent: 'app-dms',
screen: screenKey,
};
});
}

return {menus, screens};
};
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ const SearchTreeView = ({
const [parent, setParent] = useState([]);

useEffect(() => {
if (defaultParent != null) {
if (defaultParent != null && isFocused) {
setParent([EMPTY_PARENT, defaultParent]);
}
}, [defaultParent]);
}, [defaultParent, isFocused]);

const handleChangeParent = value => {
setParent(current => {
Expand Down

0 comments on commit 060b464

Please sign in to comment.