Skip to content

Commit

Permalink
Merge pull request #29 from totono/11-要望詳細入力ボタン位置変更または編集可
Browse files Browse the repository at this point in the history
11 要望詳細入力ボタン位置変更または編集可
  • Loading branch information
totono authored Apr 1, 2023
2 parents 526fcbd + aa30052 commit 3066519
Show file tree
Hide file tree
Showing 47 changed files with 1,079 additions and 542 deletions.
48 changes: 26 additions & 22 deletions src-tauri/src/entity/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
use sea_orm::entity::prelude::*;
use serde::{Serialize, Deserialize};
use ts_rs::TS;

#[derive(TS,Serialize,Deserialize,EnumIter, DeriveActiveEnum, Debug, Clone, PartialEq, Eq)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
#[ts(export)]
pub enum CompleteStatus{
#[sea_orm(num_value = 0)]
NotComplete,
#[sea_orm(num_value = 1)]
Completed,
}

#[derive(TS,Serialize, Deserialize, EnumIter, DeriveActiveEnum, Debug, Clone, PartialEq, Eq)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
#[ts(export)]
pub enum DeleteStatus{
#[sea_orm(num_value = 0)]
NotDelete,
#[sea_orm(num_value = 1)]
Deleted,
use sea_orm::entity::prelude::*;
use serde::{Serialize, Deserialize};
use ts_rs::TS;

#[derive(TS,Serialize,Deserialize,EnumIter, DeriveActiveEnum, Debug, Clone, PartialEq, Eq)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
#[ts(export)]
pub enum Completed{
No = 0,
Yes = 1,
}

#[derive(TS,Serialize, Deserialize, EnumIter, DeriveActiveEnum, Debug, Clone, PartialEq, Eq)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
#[ts(export)]
pub enum Deleted{
No = 0,
Yes = 1,
}

#[derive(TS,Serialize, Deserialize, EnumIter, DeriveActiveEnum, Debug, Clone, PartialEq, Eq)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
#[ts(export)]
pub enum ShouldNotify{
No = 0,
Yes = 1,
}
6 changes: 3 additions & 3 deletions src-tauri/src/entity/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub struct Model {
pub text: Option<String>,
pub file_path: Option<String>,
pub completed_at: Option<String>,
pub is_completed: status::CompleteStatus,
pub is_completed: status::Completed,
pub limit_date: Option<String>,
pub limit_time: Option<String>,
pub should_notify: Option<i32>,
pub should_notify: status::ShouldNotify,
pub create_at: String,
pub update_at: Option<String>,
pub deleted_at: Option<String>,
pub is_deleted: status::DeleteStatus,
pub is_deleted: status::Deleted,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fn main() {
complete_task,
logical_delete_task,
physical_delete_task,
update_text,
update_task,
])
.run(tauri::generate_context!())
.expect("error while running tauri application")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl MigrationTrait for Migration {
)
.col(ColumnDef::new(Tasks::LimitDate).date_time())
.col(ColumnDef::new(Tasks::LimitTime).date_time())
.col(ColumnDef::new(Tasks::ShouldNotify).integer())
.col(ColumnDef::new(Tasks::ShouldNotify).integer().not_null())
.col(ColumnDef::new(Tasks::CompletedAt).date_time())
.col(ColumnDef::new(Tasks::CreateAt).date_time().not_null())
.col(ColumnDef::new(Tasks::UpdateAt).date_time().not_null())
Expand Down
81 changes: 78 additions & 3 deletions src-tauri/src/mutation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::entity::{status::CompleteStatus, status::DeleteStatus, tasks, tasks::Entity as Tasks};
use ::entity::{status::Completed, status::Deleted,status::ShouldNotify, tasks, tasks::Entity as Tasks};
use chrono::*;
use sea_orm::{prelude::*, ActiveValue::Set};

Expand All @@ -10,12 +10,14 @@ pub async fn create_task(
title: String,
limit_date: String,
limit_time: Option<String>,
should_notify: ShouldNotify,
text: Option<String>,
file_path: Option<String>,
) -> Result<tasks::Model, String> {
let new_task = tasks::ActiveModel {
title: Set(title),
text: Set(text),
should_notify: Set(should_notify),
file_path: Set(file_path),
limit_date: Set(Some(limit_date)),
limit_time: Set(limit_time),
Expand All @@ -29,11 +31,84 @@ pub async fn create_task(
}
}


#[tauri::command(async)]
pub async fn update_notify_status(
state: State<'_>,
id: i32,
status: ShouldNotify,
) -> Result<tasks::Model, String> {
let db = state.db.clone();

let task = tasks::ActiveModel {
id: Set(id),
should_notify: Set(status),
..Default::default()
};

match task.update(&*db).await {
Ok(v) => Ok(v),
Err(e) => Err(format!("{e:?}")),
}
}

#[tauri::command(async)]
pub async fn update_text(
state: State<'_>,
id: i32,
text: String,
) -> Result<tasks::Model, String> {
let db = state.db.clone();

let task = tasks::ActiveModel {
id: Set(id),
text: Set(Some(text)),
..Default::default()
};

match task.update(&*db).await {
Ok(v) => Ok(v),
Err(e) => Err(format!("{e:?}")),
}
}


#[tauri::command(async)]
pub async fn update_task(
state: State<'_>,
id: i32,
title: String,
limit_date: String,
limit_time: Option<String>,
text: Option<String>,
file_path: Option<String>,
is_completed: Completed,
) -> Result<tasks::Model, String> {
let db = state.db.clone();

let task = tasks::ActiveModel {
id: Set(id),
title: Set(title),
text: Set(text),
file_path: Set(file_path),
limit_date: Set(Some(limit_date)),
limit_time: Set(limit_time),
is_completed: Set(is_completed),
..Default::default()
};

match task.update(&*db).await {
Ok(v) => Ok(v),
Err(e) => Err(format!("{e:?}")),
}
}


#[tauri::command(async)]
pub async fn complete_task(
state: State<'_>,
id: i32,
status: CompleteStatus,
status: Completed,
) -> Result<tasks::Model, String> {
let db = state.db.clone();
let current_time = Local::now().format("%Y/%M/%d %H:%M:%S").to_string();
Expand All @@ -58,7 +133,7 @@ pub async fn logical_delete_task(state: State<'_>, id: i32) -> Result<tasks::Mod

let task = tasks::ActiveModel {
id: Set(id),
is_deleted: Set(DeleteStatus::Deleted),
is_deleted: Set(Deleted::Yes),
completed_at: Set(Some(current_time)),
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ::entity::{status::CompleteStatus, status::DeleteStatus, tasks, tasks::Entity as Tasks};
use ::entity::{status::Completed, status::Deleted, tasks, tasks::Entity as Tasks};
use sea_orm::prelude::*;

use crate::store::{AppState, State};
Expand Down
Binary file modified src-tauri/store/database.db
Binary file not shown.
Binary file removed src-tauri/store/database.db-shm
Binary file not shown.
Binary file removed src-tauri/store/database.db-wal
Binary file not shown.
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** @jsxImportSource @emotion/react */
import { css, Global } from "@emotion/react";
import { Header } from "./components/elements/layouts/header";
import { Projects } from "./components/elements/layouts/projects";
import { Tasks } from "./components/elements/layouts/projects";
import { useState } from "react";
import { InputProject } from "./components/elements/Input/InputProject"
import { ConfigProvider,theme } from 'antd'
import { appWindow } from "@tauri-apps/api/window";

Expand Down Expand Up @@ -61,7 +60,7 @@ function App() {
fetch={fetch}
setFetch={setFetch}/>
<ul css={css`padding-left:0;`}>
<Projects
<Tasks
fetch={fetch}
setFetch={setFetch}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/status/CompleteStatus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type CompleteStatus = "NotComplete" | "Completed";
export type Completed = "No" | "Yes";
2 changes: 1 addition & 1 deletion src/bindings/status/DeleteStatus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type DeleteStatus = "NotDelete" | "Deleted";
export type Deleted = "No" | "Yes";
3 changes: 3 additions & 0 deletions src/bindings/status/ShouldNotify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


export type ShouldNotify = "No" | "Yes";
7 changes: 4 additions & 3 deletions src/bindings/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { CompleteStatus } from ".\\status\\CompleteStatus";
import type { DeleteStatus } from ".\\status\\DeleteStatus";
import type { Completed } from ".\\status\\CompleteStatus";
import type { Deleted } from ".\\status\\DeleteStatus";
import type { ShouldNotify } from ".\\status\\ShouldNotify";

export interface Model { id: number, title: string, text: string | null, file_path: string | null, completed_at: string | null, is_completed: CompleteStatus, limit_date: string | null, limit_time: string | null, should_notify: number | null, create_at: string, update_at: string | null, deleted_at: string | null, is_deleted: DeleteStatus, }
export interface Model { id: number, title: string, text: string | undefined, file_path: string | null, completed_at: string | null, is_completed: Completed, limit_date: string | undefined, limit_time: string | undefined, should_notify: ShouldNotify, create_at: string, update_at: string | null, deleted_at: string | null, is_deleted: Deleted, }
18 changes: 18 additions & 0 deletions src/components/elements/Input/CompleteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Model } from "../../../bindings/tasks";
import { Completed } from "../../../bindings/status/CompleteStatus";
import { taskCommand } from "../../../ipcs";
import { Button } from "antd";

export const CompleteButton = (props: any) => {
const clickHandle = (_e: any) => {
console.log(props.data);
taskCommand.setStatus(parseInt(props.data), "Yes");
props.setFetch(true);
};

return (
<Button value={props.data} onClick={clickHandle}>
Complete
</Button>
);
};
21 changes: 0 additions & 21 deletions src/components/elements/Input/CompleteCheck.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions src/components/elements/Input/DateTime/DateForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @jsxImportSource @emotion/react */
import { DatePicker} from "antd";
import { Dayjs } from "dayjs";
import { Dispatch, SetStateAction } from "react";
import { InputState } from "../InputState";
import { dateTimeStyle } from "./dateTimeStyle";


type DateFormProps = {
task: InputState;
setTask: Dispatch<SetStateAction<InputState>>;
value: Dayjs | null;
}


const dateFormat = "YYYY/MM/DD";

export const DateForm = ({task,setTask,value}:DateFormProps) => {

const handleDateInput = (date: Dayjs | null) => {
setTask({ ...task, limit_date: date?.format(dateFormat) ?? undefined });
};

return (
<DatePicker
css={dateTimeStyle}
name="date"
value={value}
onChange={handleDateInput}
format={"MM/DD"}
/>
)
}
57 changes: 57 additions & 0 deletions src/components/elements/Input/DateTime/TimeForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @jsxImportSource @emotion/react */
import { TimePicker } from "antd"
import dayjs, { Dayjs } from "dayjs";
import { Dispatch, SetStateAction, useState } from "react";
import * as objectSupport from "dayjs/plugin/objectSupport";
import { Model } from "../../../../bindings/tasks";
import { InputState } from "../InputState";
import { dateTimeStyle } from "./dateTimeStyle";


dayjs.extend(objectSupport);


const timeFormat = "HH:mm";
const disabledTime = () => {
return { disabledHours: () => [0, 1, 2, 3, 4, 5, 6, 7] }
};

type TimeFormProps = {
task: InputState;
setTask: Dispatch<SetStateAction<InputState>>;
value: string | undefined;
}


export const TimeForm = ({task,setTask,value}:TimeFormProps) => {

console.log("TimeForm");
console.log(value);

const hour = value ? parseInt(value.split(":")[0]) : undefined;
const minute = value ? parseInt(value.split(":")[1]) : undefined;

const time = value ? dayjs({hour:hour, minute:minute}) : undefined;

const handleTimeInput = (time: Dayjs | null) => {
console.log("task set");
console.log(time?.format(timeFormat));
setTask({ ...task, limit_time: time?.format(timeFormat) ?? undefined });
//console.log(task);
};

return (
<TimePicker
css = {dateTimeStyle}
name="time"
value={time}
onSelect={handleTimeInput}
onChange={handleTimeInput}
disabledTime={disabledTime}
hideDisabledOptions={true}
minuteStep={5}
format={timeFormat}
/>
)

}
Loading

0 comments on commit 3066519

Please sign in to comment.