Skip to content

Commit

Permalink
Delete and update notice and todolist (#73)
Browse files Browse the repository at this point in the history
* feat: add notices to a new collection

the new collection named todolist, and there are small changes about
how the pages look like.

* feat: add notices to a new collection

* style: update npm and run format

* style: run npm format again

* feat: update and delete notice

* feat: delete todolist

---------

Co-authored-by: sheeplin <[email protected]>
Co-authored-by: My Go! <[email protected]>
  • Loading branch information
3 people authored Mar 16, 2024
1 parent 518acf7 commit f552963
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 87 deletions.
2 changes: 2 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Checknotice from "./routes/checknotice.svelte";
import UpdateChannel from "./routes/updateChannel.svelte";
import Jumptag from "./routes/jumptag.svelte";
import InfoPage from "./routes/infoPage.svelte";
import Updatenotice from "./routes/updatenotice.svelte";
export default {
"/": DoorPage,
"/login": Login,
Expand All @@ -31,4 +32,5 @@ export default {
"/updateChannel": UpdateChannel,
"/jumptag": Jumptag,
"/infoPage": InfoPage,
"/updatenotice": Updatenotice,
};
122 changes: 63 additions & 59 deletions src/routes/mainpage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,56 @@
function editChannel(channelName) {
currentchannelName.set(channelName);
push("/updateChannel");
// const channel = createdChannels.find((c) => c.channelName === channelName);
// if (channel) {
// selectedChannel = channel;
// }
}
function editnotice(noticeid) {
currentnoticeid.set(noticeid);
push("/updatenotice");
}
function handleUpdate() {
fetchCreatedChannels(); // 重新获取频道列表
checkchan();
selectedChannel = null; // 重置selectedChannel,关闭编辑模态框
}
async function deletetodo(todoid) {
if (!confirm("确定要从待办事项中删除这则通知吗?")) {
return;
}
try {
const todos = await pb.collection("todolist").getFullList({
filter: `id="${todoid}"`,
});
for (const todo of todos) {
await pb.collection("todolist").delete(todo.id);
}
alert("删除成功。");
checkTodolist();
} catch (error) {
console.error("删除失败:", error);
alert("删除失败。");
}
}
async function deletenotice(noticeid) {
if (!confirm("确定要删除这则通知吗?")) {
return;
}
try {
const notices = await pb.collection("notices").getFullList({
filter: `id="${noticeid}"`,
});
for (const notice of notices) {
await pb.collection("notices").delete(notice.id);
}
alert("频道及相关数据删除成功。");
checkNotice();
} catch (error) {
console.error("删除频道及相关数据失败:", error);
alert("删除频道及相关数据失败。");
}
}
async function deleteChannel(channelName) {
if (!confirm("确定要删除这个频道吗?")) {
return; // 用户取消操作,直接返回
}
try {
// 查找channels集合中的指定频道
const channels = await pb.collection("channels").getFullList({
Expand Down Expand Up @@ -165,17 +198,6 @@
originChannelID.set(origin);
push("/chantemplate");
}
// async function test(id,cN){
// currentchannelid.set(id);
// alert($currentchannelid);
// push("/chantemplate");
// const response_ = await pb.collection("channels").getFullList({
// sort: "-created",
// filter: `channelName="${cN}"`,
// });
// originChannelID.set(response_[0].id);
// originChannelID.set(response_[0].id);
// }
async function checkUser() {
try {
Expand All @@ -190,26 +212,6 @@
}
}
// function sleep(ms) {
// return new Promise(resolve => setTimeout(resolve, ms));
// }
// async function updateOriginChannelId(cN) {
// try {
// const response_ = await pb.collection("channels").getFullList({
// sort: "-created",
// filter: `channelName="${cN}"`,
// });
// originChannelID.set(response_[0].id);
// originChannelID.set(response_[0].id);
// alert($originChannelID);
// } catch {
// alert("error");
// }
// }
async function jumptodo(title) {
const response_ = await pb.collection("notices").getFullList({
sort: "-created",
Expand Down Expand Up @@ -261,13 +263,8 @@
>频道管理</button
>
<Modal isOpen={showModal} close={toggleModal}>
<h2 style="color: black;">频道管理</h2>
<h2>频 道 管 理</h2>
<div class="container flex flex-col space-y-3 items-center">
<!-- {#each records as record}
<button class="button01" on:click={() => jumpnew(record.id)}
>#{record.channelname}</button
>
{/each} -->
<button
class="btn btn-primary w-2/3 text-lg"
on:click={() => JumpNewPage("createChannel")}
Expand Down Expand Up @@ -340,18 +337,11 @@
/>
{/if}
</Modal>
<!-- <button class="button-present" on:click={() => JumpNewPage("mychannel")}>
频道</button
> -->

<!-- <button class="button-present" on:click={() => JumpNewPage("mynotice")}>
通知管理
</button> -->
<button class="btn w-4/5 h-1/5 m-100 text-5xl" on:click={toggleModal3}
>通知管理</button
>
<Modal isOpen={showModal3} close={toggleModal3}>
<h2 style="color: black;">通知管理</h2>
<h2>通 知 管 理</h2>
<div class="container">
{#each recordsNotice as record}
<div
Expand All @@ -365,6 +355,14 @@
<div class="content">#{record.tag}</div>
<div class="author">from:{record.username}</div>
</div>
<div>
<button class="edit-btn" on:click={() => editnotice(record.id)}
>修改</button
>
<button class="delete-btn" on:click={() => deletenotice(record.id)}
>删除</button
>
</div>
{/each}
</div>
</Modal>
Expand All @@ -373,7 +371,7 @@
>待办事项</button
>
<Modal isOpen={showModal4} close={toggleModal4}>
<h2 style="color: black;">待办事项</h2>
<h2>待 办 事 项</h2>
<div class="container">
{#each todo as todothing}
<div
Expand All @@ -383,6 +381,9 @@
on:click={() => jumptodo(todothing.tittle)}
on:keypress
>
<button class="chacha" on:click={() => deletetodo(todothing.id)}
>x</button
>
<div class="title">{todothing.tittle}</div>
<div class="content">#{todothing.tag}</div>
<div class="author">
Expand All @@ -392,12 +393,6 @@
{/each}
</div>
</Modal>
<!-- <button
class="button-present"
on:click={() => JumpNewPage("checkInformation")}
>
待办事项
</button> -->
</div></body
>

Expand Down Expand Up @@ -549,10 +544,19 @@
background-color: #5c5c5c; /* 修改按钮悬停时的背景颜色 */
}
.chacha:hover,
.delete-btn:hover {
color: white;
background-color: #a54444; /* 删除按钮悬停时的背景颜色 */
}
.chacha {
background-color: white;
width: 20px;
color: #a3a1a1;
float: right;
text-align: center;
}
.channel-row {
display: flex;
align-items: center;
Expand Down
53 changes: 27 additions & 26 deletions src/routes/sendNotification.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,30 @@
</div>
<div>
<label for="release_time">Release_time:</label>
<select bind:value={currentYear}>
{#each years as year}
<option value={year}>{year}年</option>
{/each}
</select>
<select bind:value={currentMonth}>
{#each months as month}
<option value={month}>{month}月</option>
{/each}
</select>
<select bind:value={currentDate}>
{#each Array.from({ length: days }, (_, i) => i + 1) as day}
<option value={day}>{day}日</option>
{/each}
</select>
<div class="time">
<select bind:value={currentYear}>
{#each years as year}
<option value={year}>{year}年</option>
{/each}
</select>
<select bind:value={currentMonth}>
{#each months as month}
<option value={month}>{month}月</option>
{/each}
</select>
<select bind:value={currentDate}>
{#each Array.from({ length: days }, (_, i) => i + 1) as day}
<option value={day}>{day}日</option>
{/each}
</select>
</div>
</div>
<div>
<button type="submit" class="cancel-button"> 发布 </button>
<button type="submit" class="btn btn-primary w-1/6 text-lg"> 发布 </button>
</div>
</form>

<button on:click={cancel} class="cancel-button"> 取消 </button>
<button on:click={cancel} class="btn btn-primary w-1/6 text-lg"> 取消 </button>

<style>
div {
Expand All @@ -120,30 +122,29 @@
display: block;
font-weight: bold; /*文本粗细*/
margin-bottom: 5px; /* div元素之间的距离 */
width: 150px;
width: 20%;
margin-left: 10%;
}
input[type="text"] {
width: 80%;
width: 20%;
height: 40px;
float: left;
border: 1px solid #ccc; /* 边框 */
padding: 10px; /* 内边距 */
border-radius: 5px; /* 圆角 */
float: left;
margin-left: 20%;
}
textarea {
width: 100%;
width: 60%;
height: 400px;
padding: 10px; /* 内边距 */
font-weight: bold; /*文本粗细*/
border: 1px solid #ccc; /* 边框 */
border-radius: 5px; /* 圆角 */
}
.cancel-button {
margin-top: 10px;
justify-content: center;
float: left;
.time {
width: 55%;
}
</style>
4 changes: 2 additions & 2 deletions src/routes/updateChannel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
try {
await pb.collection("channels").update(channelId, data);
alert("Channel updated successfully");
alert("频道修改成功!");
isLoading = false;
push("/main");
} catch (error) {
Expand All @@ -49,7 +49,7 @@
}
} else {
// 如果channelId不存在,可以选择创建新频道或者显示错误消息
alert("Channel does not exist.");
alert("所选频道不存在。");
isLoading = false;
}
}
Expand Down
Loading

0 comments on commit f552963

Please sign in to comment.