-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#59 Alles Material löschen Funktion hinzugefügt #67
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Button, Popconfirm, message } from 'antd'; | ||
import {Abteilung} from 'types/abteilung.type'; | ||
import { firestore } from 'config/firebase/firebase'; | ||
import { abteilungenCollection, abteilungenMaterialsCollection} from "config/firebase/collections"; | ||
import { DeleteOutlined } from '@ant-design/icons'; | ||
import { useContext, useState } from 'react'; | ||
|
||
export interface DeleteMaterialProps { | ||
abteilung: Abteilung | ||
} | ||
|
||
export const DeleteMaterialButton = (props: DeleteMaterialProps) => { | ||
const { abteilung} = props; | ||
const [updateLoading] = useState(false); | ||
|
||
const delteMaterial = async () => { | ||
await firestore().collection(abteilungenCollection).doc(abteilung.id).collection(abteilungenMaterialsCollection).get().then((snapshot) => { | ||
snapshot.docs.forEach((doc) => { | ||
doc.ref.delete(); | ||
}); | ||
}).then(() => { | ||
message.info(`Alles Material von ${abteilung.name} wurde erfolgreich gelöscht`); | ||
}).catch((ex) => { | ||
message.error(`Es ist ein Fehler aufgetreten: ${ex}`); | ||
}); | ||
} | ||
|
||
return <> | ||
<Popconfirm | ||
title='Möchtest du wirklich alles Material dieser Abteilung löschen?' | ||
onConfirm={() => delteMaterial()} | ||
onCancel={() => { }} | ||
okText='Ja' | ||
cancelText='Nein' | ||
> | ||
<Button type='ghost' danger icon={<DeleteOutlined />} disabled={updateLoading}> | ||
Material Löschen | ||
</Button> | ||
</Popconfirm> | ||
</> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Button} from 'antd'; | ||
import {Abteilung} from 'types/abteilung.type'; | ||
import { useContext } from 'react'; | ||
import { exportMaterialsToXlsx } from 'util/ExcelUtil'; | ||
import {CategorysContext, MaterialsContext, StandorteContext} from 'components/abteilung/AbteilungDetails'; | ||
|
||
export interface ExportMaterialProps { | ||
abteilung: Abteilung | ||
} | ||
|
||
export const ExportMaterialButton = (props: ExportMaterialProps) => { | ||
const { abteilung} = props; | ||
|
||
//fetch materials | ||
const materialsContext = useContext(MaterialsContext); | ||
const materials = materialsContext.materials; | ||
const matLoading = materialsContext.loading; | ||
|
||
//fetch categories | ||
const categoriesContext = useContext(CategorysContext); | ||
const categories = categoriesContext.categories; | ||
const catLoading = categoriesContext.loading; | ||
|
||
//fetch categories | ||
const standorteContext = useContext(StandorteContext); | ||
const standorte = standorteContext.standorte; | ||
const standorteLoading = standorteContext.loading; | ||
|
||
|
||
return <> | ||
<Button type='primary' onClick={()=> exportMaterialsToXlsx(abteilung, categories, materials, standorte)}> | ||
Excel export | ||
</Button> | ||
</> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { message,Button } from 'antd'; | ||
import {Abteilung} from 'types/abteilung.type'; | ||
import { useState } from 'react'; | ||
import { ExcelJson } from 'types/excel.type'; | ||
import { ExcelImport } from './ExcelImport'; | ||
import { excelToJson } from 'util/ExcelUtil'; | ||
import React from 'react' | ||
|
||
export interface importAddMaterialProps { | ||
abteilung: Abteilung | ||
} | ||
|
||
export const ImportAddMaterialButton = (props: importAddMaterialProps) => { | ||
const { abteilung} = props; | ||
const [excelData, setExcelData] = useState<ExcelJson | undefined>(); | ||
const [showImportModal, setShowImportModal] = useState<boolean>(false); | ||
const [updateLoading] = useState(false); | ||
let excelInput = React.useRef<HTMLInputElement>(null); | ||
|
||
return <> | ||
<input | ||
style={{ display: 'none' }} | ||
type='file' | ||
name='excelFile' | ||
id='uploadExcel' | ||
ref = {excelInput} | ||
onChange={async (e) => { | ||
const res = await excelToJson(e); | ||
if(res) { | ||
setExcelData(res) | ||
setShowImportModal(true) | ||
} else { | ||
message.error('Leider ist ein Fehler beim lesen der Datei aufgetreten 2'); | ||
} | ||
}} | ||
/> | ||
<Button type='primary' disabled={updateLoading} onClick={() => excelInput?.current?.click()}> | ||
Excel Import | ||
</Button> | ||
<ExcelImport abteilung={abteilung} excelData={excelData} showModal={showImportModal} setShow={setShowImportModal}/> | ||
</> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ import moment from 'moment'; | |
import {Material} from 'types/material.types'; | ||
import {getAvailableMatCount} from 'util/MaterialUtil'; | ||
import {AddStandortButton} from "components/standort/AddStandort"; | ||
import {ImportAddMaterialButton} from 'components/material/ImportAddMaterial'; | ||
import {DeleteMaterialButton} from 'components/material/DeleteMaterial'; | ||
import {ExportMaterialButton} from 'components/material/ExportMaterial'; | ||
|
||
export type AbteilungMaterialViewProps = { | ||
abteilung: Abteilung; | ||
|
@@ -124,6 +127,18 @@ export const AbteilungMaterialView = (props: AbteilungMaterialViewProps) => { | |
<AddStandortButton abteilungId={abteilung.id} /> | ||
</Can> | ||
</Col> | ||
<Can I={'delete'} this={{ __caslSubjectType__: 'Material', abteilungId: abteilung.id } as AbteilungEntityCasl}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich bin nicht wirklich ein Fan von den Buttons unter der Navigation. Gibt es da einen besseren Weg? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UM alles Material zu löschen denke ich sollte dies beim Excel Import sein oder nicht? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wie wäre es mit einem Dropdown in der Navigation namens Aktionen von wo aus man verschiedene Aktionen ausführen kann? Entweder direkt aus dem Dropdwon das popup öffnen oder eine Subpage mit funktionen? Oder Option 2 wäre man nimmt alles zu den Einstellungen und hat dort einerseits funkionen um diverse dinge zu Bearbeiten und Erstellen sowie die Einstellungen. Findet ihr davon etwas gut? @JeremiasBachmann @Leo1212 @pemko123 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aktionen in der Navigation könnte man machen, solange es nicht zu viele werden. Unter Settings fände ich die Buttons irgendwie nicht sehr intuitiv, da Ich Buttons welche mit dem Material zu tun haben unter dem Menupunkt Material erwarten würde und nicht bei Settings. Ich finde die Buttons aber eigentlich nicht schlecht platziert, vor allem da sie ohnehin nur für das MatTeam/Admins sichtbar sind. Eine weiter Möglichkeit wäre das man für das MatTeam einen eigenen Menupunkt erstellt, in welchem sie das Mat verwalten können, und MatTeam spezifische Einstellung wie z.B. das aktivieren von Email Benachrichtigungen etc. haben. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Beim Excel Import wurde dies so umgesetzt, dass man wählen kann ob das neue Material, das alte Material ersetzten soll oder ob es zum alten Material hinzugefügt werden soll. |
||
<Col hidden={windowSize[0] < 769} xl={4}> | ||
<ImportAddMaterialButton abteilung={abteilung} /> | ||
</Col> | ||
<Col hidden={windowSize[0] < 769} xl={4}> | ||
<ExportMaterialButton abteilung={abteilung} /> | ||
</Col> | ||
<Col hidden={windowSize[0] < 769} xl={4}> | ||
<DeleteMaterialButton abteilung={abteilung} /> | ||
</Col> | ||
</Can> | ||
|
||
|
||
{ | ||
matLoading || catLoading ? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kleiner Typo ;)