problem solved
This commit is contained in:
parent
dc66da7d00
commit
365e2e3982
@ -6,6 +6,7 @@ import { Attributes, where } from "@sequelize/core";
|
|||||||
import { getCookieAuth, userIsAdmin } from '../../actions';
|
import { getCookieAuth, userIsAdmin } from '../../actions';
|
||||||
import { ActionResult } from '../../ActionResult';
|
import { ActionResult } from '../../ActionResult';
|
||||||
import { PostAttributesWithBuckets } from '@/models';
|
import { PostAttributesWithBuckets } from '@/models';
|
||||||
|
import { inspect } from 'util';
|
||||||
|
|
||||||
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
|
export async function deletePost(postID: number): Promise<ActionResult<boolean>> {
|
||||||
await dbSync;
|
await dbSync;
|
||||||
@ -30,7 +31,7 @@ export type GetPostsAttributes = {
|
|||||||
export async function getPostsWithBucketsAndProject(): Promise<ActionResult<GetPostsAttributes[]>> {
|
export async function getPostsWithBucketsAndProject(): Promise<ActionResult<GetPostsAttributes[]>> {
|
||||||
await dbSync;
|
await dbSync;
|
||||||
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
|
if(! await userIsAdmin()) return {error:"Unauthorized, not fetching Posts."}
|
||||||
const posts = await Post.findAll({
|
const posts:Post[] = await Post.findAll({
|
||||||
include: [
|
include: [
|
||||||
{association: Post.associations.buckets, include: Bucket.associations.attachments},
|
{association: Post.associations.buckets, include: Bucket.associations.attachments},
|
||||||
{association: Post.associations.user},
|
{association: Post.associations.user},
|
||||||
@ -38,22 +39,7 @@ export async function getPostsWithBucketsAndProject(): Promise<ActionResult<GetP
|
|||||||
nest: false
|
nest: false
|
||||||
});
|
});
|
||||||
return {result:JSON.parse(JSON.stringify(posts.map((e:Post)=>{
|
return {result:JSON.parse(JSON.stringify(posts.map((e:Post)=>{
|
||||||
return {
|
return inspect(e)
|
||||||
id: e.id,
|
|
||||||
title: e.title,
|
|
||||||
content: e.content,
|
|
||||||
description: e.description,
|
|
||||||
buckets: e.buckets ? e.buckets : [],
|
|
||||||
user: e.user,
|
|
||||||
project: {
|
|
||||||
id: e.project_id,
|
|
||||||
name: e.project ? e.project.name : "",
|
|
||||||
readableIdentifier: e.project ? e.project.readableIdentifier : "",
|
|
||||||
posts: e.project ? e.project.posts : []
|
|
||||||
},
|
|
||||||
createdAt: e.createdAt,
|
|
||||||
updatedAt: e.updatedAt
|
|
||||||
} as GetPostsAttributes
|
|
||||||
})))};
|
})))};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,9 @@
|
|||||||
import { GetPostsAttributes } from "@/app/lib/actions/entityManagement/post/postActions";
|
import { GetPostsAttributes } from "@/app/lib/actions/entitymanagement/post/postActions";
|
||||||
import { Post, Project, Bucket, PostBucket, Attachment } from "@/models";
|
import { Post, Project, Bucket, PostBucket, Attachment } from "@/models";
|
||||||
import { Attributes } from "@sequelize/core";
|
import { Attributes } from "@sequelize/core";
|
||||||
import { UUID } from "crypto";
|
import { UUID } from "crypto";
|
||||||
import { EntityEditorTextArea } from '../input/EntityEditorTextArea';
|
import { EntityEditorTextArea } from "../input/EntityEditorTextArea";
|
||||||
import {
|
import { ChangeEvent, ChangeEventHandler, MouseEventHandler, useState } from "react";
|
||||||
ChangeEventHandler,
|
|
||||||
MouseEventHandler,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionBody,
|
AccordionBody,
|
||||||
@ -86,11 +82,12 @@ export default function PostEditor({
|
|||||||
<EntityEditorTextArea
|
<EntityEditorTextArea
|
||||||
contentHook={{
|
contentHook={{
|
||||||
state: postContentState,
|
state: postContentState,
|
||||||
setState: setPostContentState
|
setState: setPostContentState,
|
||||||
}}
|
}}
|
||||||
className={ "w-[100%] min-h-auto h-content align-top text-start text-base line-clamp-6 m-2" }
|
className={
|
||||||
>
|
"w-[100%] min-h-auto h-content align-top text-start text-base line-clamp-6 m-2"
|
||||||
</EntityEditorTextArea>
|
}
|
||||||
|
></EntityEditorTextArea>
|
||||||
<h2 key="label-project" className="m-2">
|
<h2 key="label-project" className="m-2">
|
||||||
Project
|
Project
|
||||||
</h2>
|
</h2>
|
||||||
@ -108,10 +105,7 @@ export default function PostEditor({
|
|||||||
unassigned
|
unassigned
|
||||||
</option>
|
</option>
|
||||||
{projectList?.map((p) => (
|
{projectList?.map((p) => (
|
||||||
<option
|
<option key={`projectSelectionOpt-${p.id}`} value={p.id}>
|
||||||
key={`projectSelectionOpt-${p.id}`}
|
|
||||||
value={p.id}
|
|
||||||
>
|
|
||||||
{p.readableIdentifier}
|
{p.readableIdentifier}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
@ -126,104 +120,40 @@ export default function PostEditor({
|
|||||||
<tbody>
|
<tbody>
|
||||||
{editorPost?.buckets ? (
|
{editorPost?.buckets ? (
|
||||||
(() => {
|
(() => {
|
||||||
let bucketMap: Map<
|
let bucketMap: Map<UUID, Attributes<Bucket>> = new Map(
|
||||||
UUID,
|
editorPost.buckets.map((b) => [b.id as UUID, b])
|
||||||
Attributes<Bucket>
|
|
||||||
> = new Map(
|
|
||||||
editorPost.buckets.map((b) => [
|
|
||||||
b.id as UUID,
|
|
||||||
b,
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
let bucketList = [
|
let bucketList:UUID[] = [...editorPost.buckets.map((b) => b.id)];
|
||||||
...editorPost.buckets.map((b) => b.id),
|
return bucketList.map((bucketID,i) => {
|
||||||
];
|
|
||||||
return bucketList.map((e) => {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<tr
|
<tr
|
||||||
key={`bucketAccordionRow-${bucketList
|
key={i}
|
||||||
.indexOf(e)
|
|
||||||
.toString()}`}
|
|
||||||
>
|
>
|
||||||
<Accordion>
|
<Accordion>
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
eventKey={bucketList
|
eventKey={bucketList.indexOf(bucketID).toString()}
|
||||||
.indexOf(e)
|
|
||||||
.toString()}
|
|
||||||
>
|
>
|
||||||
<AccordionHeader>
|
<AccordionHeader>{bucketID}</AccordionHeader>
|
||||||
{e}
|
|
||||||
</AccordionHeader>
|
|
||||||
<AccordionBody>
|
<AccordionBody>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
className="btn btn-success"
|
className="btn btn-success"
|
||||||
onChange={(
|
onChange={onFileInputChange()}
|
||||||
e
|
|
||||||
) => {
|
|
||||||
for (
|
|
||||||
let index = 0;
|
|
||||||
index <
|
|
||||||
((
|
|
||||||
e
|
|
||||||
.target
|
|
||||||
.files as FileList
|
|
||||||
)
|
|
||||||
.length as number);
|
|
||||||
index++
|
|
||||||
) {
|
|
||||||
const element =
|
|
||||||
(
|
|
||||||
e
|
|
||||||
.target
|
|
||||||
.files as FileList
|
|
||||||
)[
|
|
||||||
index
|
|
||||||
];
|
|
||||||
const fReader =
|
|
||||||
new FileReader();
|
|
||||||
fReader.readAsDataURL(
|
|
||||||
element
|
|
||||||
);
|
|
||||||
fReader.onloadend =
|
|
||||||
(
|
|
||||||
event
|
|
||||||
) => {
|
|
||||||
console.log(
|
|
||||||
event
|
|
||||||
.target
|
|
||||||
?.result
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
{(() => {
|
{(() => {
|
||||||
const bucket =
|
const bucket: Attributes<Bucket> | undefined = bucketMap.get(bucketID);
|
||||||
bucketMap.get(
|
return bucket && bucket.attachments && (
|
||||||
e as UUID
|
bucket.attachments.map((attachment) => (
|
||||||
);
|
|
||||||
return bucket &&
|
|
||||||
bucket.attachments ? (
|
|
||||||
bucket.attachments.map(
|
|
||||||
(
|
|
||||||
attachment
|
|
||||||
) => (
|
|
||||||
<li
|
<li
|
||||||
key={`listItem-file-${attachment.filename}`}
|
key={`listItem-file-${attachment.filename}`}
|
||||||
>
|
>
|
||||||
{
|
{attachment.filename}
|
||||||
attachment.filename
|
|
||||||
}
|
|
||||||
</li>
|
</li>
|
||||||
)
|
))
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
</ul>
|
</ul>
|
||||||
@ -271,6 +201,23 @@ type EditorRendererProps = {
|
|||||||
projects: any;
|
projects: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function onFileInputChange(): ChangeEventHandler<HTMLInputElement> {
|
||||||
|
return (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
for (let index = 0; index <
|
||||||
|
((e.target.files as FileList)
|
||||||
|
.length as number); index++) {
|
||||||
|
const element = (
|
||||||
|
e.target.files as FileList
|
||||||
|
)[index];
|
||||||
|
const fReader = new FileReader();
|
||||||
|
fReader.readAsDataURL(element);
|
||||||
|
fReader.onloadend = (event) => {
|
||||||
|
console.log(event.target?.result);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function EditorRenderer({
|
export function EditorRenderer({
|
||||||
editorPost,
|
editorPost,
|
||||||
headings,
|
headings,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user