Compare commits
274 commits
5803c7b29b
...
c1f49915ba
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c1f49915ba | ||
![]() |
2aaa327a01 | ||
![]() |
05545f6f88 | ||
![]() |
0792c6b8a3 | ||
![]() |
45e891ed2c | ||
![]() |
1db1b84e8f | ||
![]() |
0cd0c8d832 | ||
![]() |
4538a3b193 | ||
![]() |
b927fb80fb | ||
![]() |
1d5fcd61b6 | ||
![]() |
13d3035e49 | ||
![]() |
c466a98b15 | ||
![]() |
9edcc74ee2 | ||
![]() |
8d7d815745 | ||
![]() |
09f2a2202f | ||
![]() |
5d714bbacf | ||
![]() |
9a54175d49 | ||
![]() |
f6dcdcc376 | ||
![]() |
218b0b3ab7 | ||
![]() |
a96f0fb488 | ||
![]() |
48e53b8768 | ||
![]() |
3d9bd2ef96 | ||
![]() |
50042ded41 | ||
![]() |
4a71078f2a | ||
![]() |
c002f0e530 | ||
![]() |
6a7bb9ab26 | ||
![]() |
cc186f8ad0 | ||
![]() |
e589726ab2 | ||
![]() |
37d06b10be | ||
![]() |
48e4d1a8df | ||
![]() |
6a78e67e7e | ||
![]() |
7c46797634 | ||
![]() |
cef7b34092 | ||
![]() |
9052babaae | ||
![]() |
752d366cf7 | ||
![]() |
19cb8dbd94 | ||
![]() |
b6d1a2926e | ||
![]() |
dc3f91eee1 | ||
![]() |
0299bb4779 | ||
![]() |
99a1430188 | ||
![]() |
36c158b54b | ||
![]() |
d4cc556366 | ||
![]() |
7c73a01d4c | ||
![]() |
0fc8957e55 | ||
![]() |
e1b410c850 | ||
![]() |
94f36d4e06 | ||
![]() |
96238ceb2e | ||
![]() |
42a2ad02e4 | ||
![]() |
492cfed08c | ||
![]() |
6ed53fe94a | ||
![]() |
dbbe4da401 | ||
![]() |
8d739396a1 | ||
![]() |
689daf4e1f | ||
![]() |
1d054e660c | ||
![]() |
589a135bb5 | ||
![]() |
4c22ba478d | ||
![]() |
deeff6c3c2 | ||
![]() |
e47f12c6d7 | ||
![]() |
b656204457 | ||
![]() |
9f931a2643 | ||
![]() |
a31a50965f | ||
![]() |
ebc59e0c11 | ||
![]() |
d8a73329a1 | ||
![]() |
1b20173ece | ||
![]() |
4b6c93a202 | ||
![]() |
70e6cbf12e | ||
![]() |
856ae40900 | ||
![]() |
ec362cfa3a | ||
![]() |
e2d2310275 | ||
![]() |
85be4c79d6 | ||
![]() |
ae0208ff23 | ||
![]() |
14133a9f22 | ||
![]() |
c415539904 | ||
![]() |
01a6f9e61d | ||
![]() |
faf998e652 | ||
![]() |
c9e28e9b5b | ||
![]() |
b2db9c54ca | ||
![]() |
c5bc6c1c58 | ||
![]() |
2694beb0e8 | ||
![]() |
a73432669c | ||
![]() |
e9eb2e9ab6 | ||
![]() |
2d4ff7e087 | ||
![]() |
baf11f19d6 | ||
![]() |
b484346031 | ||
![]() |
1950112202 | ||
![]() |
3e11b87eee | ||
![]() |
9e2a3cca81 | ||
![]() |
dea802bd91 | ||
![]() |
ed88220a47 | ||
![]() |
d4547e997c | ||
![]() |
89ba0415f7 | ||
![]() |
13720d633f | ||
![]() |
a3bf3a04ac | ||
![]() |
6bc09c656a | ||
![]() |
44f6b31056 | ||
![]() |
e7acfb37b1 | ||
![]() |
a6d7ee2de6 | ||
![]() |
acdee28eb0 | ||
![]() |
03f6edd320 | ||
![]() |
e63b45f38a | ||
![]() |
e8262ed5e0 | ||
![]() |
6dfc31832c | ||
![]() |
b2333d8cbd | ||
![]() |
e839d02cfd | ||
![]() |
3f2e104078 | ||
![]() |
28935f285b | ||
![]() |
01b934969a | ||
![]() |
b7523cf04d | ||
![]() |
a2a8ccd185 | ||
![]() |
8aa9e285b8 | ||
![]() |
afa445a426 | ||
![]() |
740289decc | ||
![]() |
a4bd2c9315 | ||
![]() |
1a87effc3a | ||
![]() |
ddea76e24a | ||
![]() |
fdaba36d57 | ||
![]() |
c4b8bef7f8 | ||
![]() |
d0209094a9 | ||
![]() |
f91f0ff8f5 | ||
![]() |
1a7bc9c73c | ||
![]() |
b00ce7a0ed | ||
![]() |
ec138163c6 | ||
![]() |
c995dc52ad | ||
![]() |
a51d984229 | ||
![]() |
70cf40feb5 | ||
![]() |
0dc7e3bf99 | ||
![]() |
65101384e2 | ||
![]() |
900797facc | ||
![]() |
4288b064f3 | ||
![]() |
cdea2dce1c | ||
![]() |
49ca043157 | ||
![]() |
b9b17bf229 | ||
![]() |
69d07624ce | ||
![]() |
22f4fba36a | ||
![]() |
ae77bcf0bb | ||
![]() |
9f61a36a68 | ||
![]() |
a9e515925e | ||
![]() |
91c9f50491 | ||
![]() |
e8c660705f | ||
![]() |
be3adb09ae | ||
![]() |
8fbb4be0ad | ||
![]() |
eff14516b4 | ||
![]() |
9bf00e8dce | ||
![]() |
3525598df2 | ||
![]() |
e4a0246b84 | ||
![]() |
9b30b82237 | ||
![]() |
bca12151b7 | ||
![]() |
8250c92694 | ||
![]() |
d1be752ac3 | ||
![]() |
bef8a6af85 | ||
![]() |
45761dadcb | ||
![]() |
0017e9b9ef | ||
![]() |
bf59503517 | ||
![]() |
933191b076 | ||
![]() |
b405b44460 | ||
![]() |
cc013632a7 | ||
![]() |
154c2240c8 | ||
![]() |
d19372d66b | ||
![]() |
cd452459c2 | ||
![]() |
056ca3660d | ||
![]() |
1147a216ce | ||
![]() |
649a4ba1fd | ||
![]() |
49e3542dce | ||
![]() |
88f232e21b | ||
![]() |
e4f5fbda44 | ||
![]() |
b99de71c38 | ||
![]() |
0befc4c7d1 | ||
![]() |
a3fc71f4bf | ||
![]() |
4030031ce9 | ||
![]() |
ef6c3951fd | ||
![]() |
dd02c2c5c6 | ||
![]() |
287e97fe6f | ||
![]() |
67680e2616 | ||
![]() |
0f4c3ac5ec | ||
![]() |
75e835895a | ||
![]() |
d94f21ab67 | ||
![]() |
ebb009bd20 | ||
![]() |
32d9cc4684 | ||
![]() |
d3938f76e1 | ||
![]() |
8084f722b5 | ||
![]() |
caa793d036 | ||
![]() |
196446be1f | ||
![]() |
0076a9f4bb | ||
![]() |
847073c6f8 | ||
![]() |
54e42cd2a8 | ||
![]() |
af5813681d | ||
![]() |
7d30165465 | ||
![]() |
771118f85e | ||
![]() |
7799eb09e9 | ||
![]() |
a84c2c6129 | ||
![]() |
eddf678f3a | ||
![]() |
14b68e4463 | ||
![]() |
47ce986834 | ||
![]() |
c6969b9503 | ||
![]() |
0fb06790af | ||
![]() |
89cb3d23b7 | ||
![]() |
adf9500bbf | ||
![]() |
00f72df65f | ||
![]() |
74e1347162 | ||
![]() |
4574af25cb | ||
![]() |
d41bfcf888 | ||
![]() |
29d893362c | ||
![]() |
c7c38d4201 | ||
![]() |
d9068949cd | ||
![]() |
7e7dbe2cc7 | ||
![]() |
cf6c8cd34c | ||
![]() |
dbeeb609b3 | ||
![]() |
aa5c4017bb | ||
![]() |
4212dae5bf | ||
![]() |
bd27b549aa | ||
![]() |
af92f4faee | ||
![]() |
2dffffde50 | ||
![]() |
c0e03d7d0d | ||
![]() |
ff4ea47846 | ||
![]() |
d3bb6f49e5 | ||
![]() |
a18ce465de | ||
![]() |
3515a86bbb | ||
![]() |
1b21b2574a | ||
![]() |
33b269e0c9 | ||
![]() |
cea2b6c03c | ||
![]() |
1919b7cb99 | ||
![]() |
ae96f67630 | ||
![]() |
6317c7674c | ||
![]() |
e271794b57 | ||
![]() |
a5adec82e2 | ||
![]() |
bb93cef1d3 | ||
![]() |
c01dd21b0a | ||
![]() |
dce91943b3 | ||
![]() |
7ed9398bcb | ||
![]() |
cd74758b2f | ||
![]() |
6c433208ea | ||
![]() |
a468b896db | ||
![]() |
033268f4ef | ||
![]() |
7b78767f50 | ||
![]() |
b13a8b5432 | ||
![]() |
4630fb336f | ||
![]() |
4e100229f5 | ||
![]() |
b20817ec8a | ||
![]() |
cc231dbfaa | ||
![]() |
8300fb3a6f | ||
![]() |
b7b831d869 | ||
![]() |
b5d3ab7cb7 | ||
![]() |
863a14c316 | ||
![]() |
cb44954477 | ||
![]() |
ffaa661628 | ||
![]() |
900c1614e9 | ||
![]() |
cd2a81e7f2 | ||
![]() |
cc9678f375 | ||
![]() |
fe89ae0970 | ||
![]() |
1974607fc7 | ||
![]() |
55a2dc7fac | ||
![]() |
d355b55634 | ||
![]() |
08a0ebb533 | ||
![]() |
63fd2e9b6f | ||
![]() |
dc6ce4b725 | ||
![]() |
05b9740c36 | ||
![]() |
3fea87a88a | ||
![]() |
0b6edd359e | ||
![]() |
e48bf5d98c | ||
![]() |
88c53ae4b6 | ||
![]() |
382ea38558 | ||
![]() |
74285dc1cf | ||
![]() |
ce4cf788ae | ||
![]() |
5778d6e892 | ||
![]() |
2b41085865 | ||
![]() |
a72aea1382 | ||
![]() |
cd84a2bb21 | ||
![]() |
8dfe9dac96 | ||
![]() |
4568d68746 | ||
![]() |
4bcbf162f9 | ||
![]() |
9c4ce0e733 | ||
![]() |
2f3730ca90 | ||
![]() |
5f6977354f | ||
![]() |
ab313551c9 |
111 changed files with 4658 additions and 1183 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -9,11 +9,16 @@ bin
|
|||
database.txt
|
||||
plantuml.jar
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
diagram.puml
|
||||
backend/*.png
|
||||
backend/*.jpg
|
||||
backend/*.svg
|
||||
|
||||
/go.work.sum
|
||||
/package-lock.json
|
||||
/backend/docs/swagger.json
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
|
|
5
Justfile
5
Justfile
|
@ -15,7 +15,7 @@ remove-podman-containers:
|
|||
|
||||
# Saves the release container to a tarball, pigz is just gzip but multithreaded
|
||||
save-release: build-container-release
|
||||
podman save --format=oci-archive ttime-server | pigz -9 > ttime-server.tar.gz
|
||||
podman save --format=oci-archive ttime-server | pigz -9 > ttime-server_`date -I`_`git rev-parse --short HEAD`.tar.gz
|
||||
|
||||
# Loads the release container from a tarball
|
||||
load-release file:
|
||||
|
@ -23,10 +23,13 @@ load-release file:
|
|||
|
||||
# Tests every part of the project
|
||||
testall:
|
||||
cd frontend && npm install
|
||||
cd frontend && npm test
|
||||
cd frontend && npm run lint
|
||||
cd frontend && npm run build
|
||||
cd backend && make test
|
||||
cd backend && make lint
|
||||
cd backend && make itest
|
||||
|
||||
# Cleans up everything related to the project
|
||||
clean: remove-podman-containers
|
||||
|
|
3
Makefile
3
Makefile
|
@ -13,10 +13,13 @@ remove-podman-containers:
|
|||
|
||||
# Tests every part of the project
|
||||
testall:
|
||||
cd frontend && npm install
|
||||
cd frontend && npm test
|
||||
cd frontend && npm run lint
|
||||
cd frontend && npm run build
|
||||
cd backend && make test
|
||||
cd backend && make lint
|
||||
cd backend && make itest
|
||||
|
||||
# Cleans up everything related to the project
|
||||
clean: remove-podman-containers
|
||||
|
|
|
@ -8,17 +8,19 @@ GOGET = $(GOCMD) get
|
|||
# SQLite database filename
|
||||
DB_FILE = db.sqlite3
|
||||
|
||||
PROC_NAME = ttime_server
|
||||
|
||||
# Directory containing migration SQL scripts
|
||||
MIGRATIONS_DIR = internal/database/migrations
|
||||
SAMPLE_DATA_DIR = internal/database/sample_data
|
||||
|
||||
# Build target
|
||||
build:
|
||||
$(GOBUILD) -o bin/server main.go
|
||||
$(GOBUILD) -o bin/$(PROC_NAME) main.go
|
||||
|
||||
# Run target
|
||||
run: build
|
||||
./bin/server
|
||||
./bin/$(PROC_NAME)
|
||||
|
||||
watch: build
|
||||
watchexec -c -w . -r make run
|
||||
|
@ -37,6 +39,16 @@ clean:
|
|||
test: db.sqlite3
|
||||
$(GOTEST) ./... -count=1
|
||||
|
||||
# Integration test target
|
||||
.PHONY: itest
|
||||
itest:
|
||||
pgrep $(PROC_NAME) && echo "Server already running" && exit 1 || true
|
||||
make build
|
||||
./bin/$(PROC_NAME) >/dev/null 2>&1 &
|
||||
sleep 1 # Adjust if needed
|
||||
python ../testing.py
|
||||
pkill $(PROC_NAME)
|
||||
|
||||
# Get dependencies target
|
||||
deps:
|
||||
$(GOGET) -v ./...
|
||||
|
@ -92,6 +104,16 @@ default: build
|
|||
docs:
|
||||
swag init -outputTypes go
|
||||
|
||||
api: ./docs/swagger.json
|
||||
npx swagger-typescript-api \
|
||||
--api-class-name GenApi \
|
||||
--path ./docs/swagger.json \
|
||||
--output ../frontend/src/API \
|
||||
--name GenApi.ts \
|
||||
|
||||
./docs/swagger.json:
|
||||
swag init -outputTypes json
|
||||
|
||||
.PHONY: docfmt
|
||||
docfmt:
|
||||
swag fmt
|
||||
|
@ -130,4 +152,12 @@ install-just:
|
|||
|
||||
.PHONY: types
|
||||
types:
|
||||
tygo generate
|
||||
tygo generate
|
||||
|
||||
.PHONY: install-golds
|
||||
install-golds:
|
||||
go install go101.org/golds@latest
|
||||
|
||||
.PHONY: golds
|
||||
golds:
|
||||
golds -port 6060 -nouses -plainsrc -wdpkgs-listing=promoted ./...
|
||||
|
|
|
@ -137,13 +137,13 @@ const docTemplate = `{
|
|||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successfully prometed user",
|
||||
"description": "Successfully promoted user",
|
||||
"schema": {
|
||||
"type": "json"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "bad request",
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
@ -5,8 +5,12 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
// TestNewConfig tests the creation of a new configuration object
|
||||
func TestNewConfig(t *testing.T) {
|
||||
// Arrange
|
||||
c := NewConfig()
|
||||
|
||||
// Act & Assert
|
||||
if c.Port != 8080 {
|
||||
t.Errorf("Expected port to be 8080, got %d", c.Port)
|
||||
}
|
||||
|
@ -24,9 +28,15 @@ func TestNewConfig(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestWriteConfig tests the function to write the configuration to a file
|
||||
func TestWriteConfig(t *testing.T) {
|
||||
// Arrange
|
||||
c := NewConfig()
|
||||
|
||||
//Act
|
||||
err := c.WriteConfigToFile("test.toml")
|
||||
|
||||
// Assert
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %s", err)
|
||||
}
|
||||
|
@ -35,14 +45,23 @@ func TestWriteConfig(t *testing.T) {
|
|||
_ = os.Remove("test.toml")
|
||||
}
|
||||
|
||||
// TestReadConfig tests the function to read the configuration from a file
|
||||
func TestReadConfig(t *testing.T) {
|
||||
// Arrange
|
||||
c := NewConfig()
|
||||
|
||||
// Act
|
||||
err := c.WriteConfigToFile("test.toml")
|
||||
|
||||
// Assert
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %s", err)
|
||||
}
|
||||
|
||||
// Act
|
||||
c2, err := ReadConfigFromFile("test.toml")
|
||||
|
||||
// Assert
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %s", err)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"ttime/internal/types"
|
||||
|
||||
|
@ -19,12 +20,14 @@ type Database interface {
|
|||
PromoteToAdmin(username string) error
|
||||
GetUserId(username string) (int, error)
|
||||
AddProject(name string, description string, username string) error
|
||||
DeleteProject(name string, username string) error
|
||||
Migrate() error
|
||||
MigrateSampleData() error
|
||||
GetProjectId(projectname string) (int, error)
|
||||
AddWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
||||
AddUserToProject(username string, projectname string, role string) error
|
||||
ChangeUserRole(username string, projectname string, role string) error
|
||||
ChangeUserName(username string, newname string) error
|
||||
GetAllUsersProject(projectname string) ([]UserProjectMember, error)
|
||||
GetAllUsersApplication() ([]string, error)
|
||||
GetProjectsForUser(username string) ([]types.Project, error)
|
||||
|
@ -32,8 +35,14 @@ type Database interface {
|
|||
GetProject(projectId int) (types.Project, error)
|
||||
GetUserRole(username string, projectname string) (string, error)
|
||||
GetWeeklyReport(username string, projectName string, week int) (types.WeeklyReport, error)
|
||||
GetWeeklyReportsUser(username string, projectname string) ([]types.WeeklyReportList, error)
|
||||
GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error)
|
||||
SignWeeklyReport(reportId int, projectManagerId int) error
|
||||
IsSiteAdmin(username string) (bool, error)
|
||||
IsProjectManager(username string, projectname string) (bool, error)
|
||||
GetProjectTimes(projectName string) (map[string]int, error)
|
||||
UpdateWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
||||
RemoveProject(projectname string) error
|
||||
}
|
||||
|
||||
// This struct is a wrapper type that holds the database connection
|
||||
|
@ -55,19 +64,27 @@ var sampleData embed.FS
|
|||
|
||||
// TODO: Possibly break these out into separate files bundled with the embed package?
|
||||
const userInsert = "INSERT INTO users (username, password) VALUES (?, ?)"
|
||||
const projectInsert = "INSERT INTO projects (name, description, owner_user_id) SELECT ?, ?, id FROM users WHERE username = ?"
|
||||
const projectInsert = "INSERT INTO projects (name, description, owner_user_id) VALUES (?, ?, (SELECT id FROM users WHERE username = ?))"
|
||||
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
|
||||
const addWeeklyReport = `WITH UserLookup AS (SELECT id FROM users WHERE username = ?),
|
||||
ProjectLookup AS (SELECT id FROM projects WHERE name = ?)
|
||||
INSERT INTO weekly_reports (project_id, user_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time)
|
||||
VALUES ((SELECT id FROM ProjectLookup), (SELECT id FROM UserLookup),?, ?, ?, ?, ?, ?, ?);`
|
||||
const addUserToProject = "INSERT INTO user_roles (user_id, project_id, p_role) VALUES (?, ?, ?)" // WIP
|
||||
const changeUserRole = "UPDATE user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?"
|
||||
|
||||
const addUserToProject = `INSERT OR IGNORE INTO user_roles (user_id, project_id, p_role)
|
||||
VALUES ((SELECT id FROM users WHERE username = ?),
|
||||
(SELECT id FROM projects WHERE name = ?), ?)`
|
||||
const changeUserRole = "UPDATE user_roles SET p_role = ? WHERE user_id = (SELECT id FROM users WHERE username = ?) AND project_id = (SELECT id FROM projects WHERE name = ?)"
|
||||
const getProjectsForUser = `SELECT p.id, p.name, p.description FROM projects p
|
||||
JOIN user_roles ur ON p.id = ur.project_id
|
||||
JOIN users u ON ur.user_id = u.id
|
||||
WHERE u.username = ?`
|
||||
const deleteProject = `DELETE FROM projects
|
||||
WHERE id = ? AND owner_username = ?`
|
||||
|
||||
const isProjectManagerQuery = `SELECT COUNT(*) > 0 FROM user_roles
|
||||
JOIN users ON user_roles.user_id = users.id
|
||||
JOIN projects ON user_roles.project_id = projects.id
|
||||
WHERE users.username = ? AND projects.name = ? AND user_roles.p_role = 'project_manager'`
|
||||
|
||||
// DbConnect connects to the database
|
||||
func DbConnect(dbpath string) Database {
|
||||
|
@ -125,42 +142,23 @@ func (d *Db) AddWeeklyReport(projectName string, userName string, week int, deve
|
|||
}
|
||||
|
||||
// AddUserToProject adds a user to a project with a specified role.
|
||||
func (d *Db) AddUserToProject(username string, projectname string, role string) error { // WIP
|
||||
var userid int
|
||||
userid, err := d.GetUserId(username)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var projectid int
|
||||
projectid, err2 := d.GetProjectId(projectname)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
|
||||
_, err3 := d.Exec(addUserToProject, userid, projectid, role)
|
||||
return err3
|
||||
func (d *Db) AddUserToProject(username string, projectname string, role string) error {
|
||||
_, err := d.Exec(addUserToProject, username, projectname, role)
|
||||
return err
|
||||
}
|
||||
|
||||
// ChangeUserRole changes the role of a user within a project.
|
||||
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
||||
// Get the user ID
|
||||
var userid int
|
||||
userid, err := d.GetUserId(username)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get the project ID
|
||||
var projectid int
|
||||
projectid, err2 := d.GetProjectId(projectname)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
|
||||
// Execute the SQL query to change the user's role
|
||||
_, err3 := d.Exec(changeUserRole, role, userid, projectid)
|
||||
return err3
|
||||
_, err := d.Exec(changeUserRole, role, username, projectname)
|
||||
return err
|
||||
}
|
||||
|
||||
// ChangeUserName changes the username of a user.
|
||||
func (d *Db) ChangeUserName(username string, newname string) error {
|
||||
// Execute the SQL query to update the username
|
||||
_, err := d.Exec("UPDATE users SET username = ? WHERE username = ?", newname, username)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetUserRole retrieves the role of a user within a project.
|
||||
|
@ -202,6 +200,7 @@ func (d *Db) GetProjectId(projectname string) (int, error) {
|
|||
// Creates a new project in the database, associated with a user
|
||||
func (d *Db) AddProject(name string, description string, username string) error {
|
||||
tx := d.MustBegin()
|
||||
// Insert the project into the database
|
||||
_, err := tx.Exec(projectInsert, name, description, username)
|
||||
if err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
|
@ -209,7 +208,9 @@ func (d *Db) AddProject(name string, description string, username string) error
|
|||
}
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(changeUserRole, "project_manager", username, name)
|
||||
|
||||
// Add creator to project as project manager
|
||||
_, err = tx.Exec(addUserToProject, username, name, "project_manager")
|
||||
if err != nil {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
return err
|
||||
|
@ -223,6 +224,21 @@ func (d *Db) AddProject(name string, description string, username string) error
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Db) DeleteProject(projectID string, username string) error {
|
||||
tx := d.MustBegin()
|
||||
|
||||
_, err := tx.Exec(deleteProject, projectID, username)
|
||||
|
||||
if err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
return fmt.Errorf("error rolling back transaction: %v, delete error: %v", rollbackErr, err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Db) GetAllUsersProject(projectname string) ([]UserProjectMember, error) {
|
||||
// Define the SQL query to fetch users and their roles for a given project
|
||||
query := `
|
||||
|
@ -340,6 +356,51 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Db) GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error) {
|
||||
// Define the SQL query to fetch unsigned reports for a given user
|
||||
query := `
|
||||
SELECT
|
||||
report_id,
|
||||
user_id,
|
||||
project_id,
|
||||
week,
|
||||
development_time,
|
||||
meeting_time,
|
||||
admin_time,
|
||||
own_work_time,
|
||||
study_time,
|
||||
testing_time,
|
||||
signed_by
|
||||
FROM
|
||||
weekly_reports
|
||||
WHERE
|
||||
signed_by IS NULL
|
||||
AND project_id = (SELECT id FROM projects WHERE name = ?)
|
||||
`
|
||||
|
||||
// Execute the query
|
||||
rows, err := d.Queryx(query, projectName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
// Iterate over the rows and populate the result slice
|
||||
var reports []types.WeeklyReport
|
||||
for rows.Next() {
|
||||
var report types.WeeklyReport
|
||||
if err := rows.StructScan(&report); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reports = append(reports, report)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return reports, nil
|
||||
}
|
||||
|
||||
// IsSiteAdmin checks if a given username is a site admin
|
||||
func (d *Db) IsSiteAdmin(username string) (bool, error) {
|
||||
// Define the SQL query to check if the user is a site admin
|
||||
|
@ -402,6 +463,63 @@ func (d *Db) Migrate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetWeeklyReportsUser retrieves weekly reports for a specific user and project.
|
||||
func (d *Db) GetWeeklyReportsUser(username string, projectName string) ([]types.WeeklyReportList, error) {
|
||||
query := `
|
||||
SELECT
|
||||
wr.week,
|
||||
wr.development_time,
|
||||
wr.meeting_time,
|
||||
wr.admin_time,
|
||||
wr.own_work_time,
|
||||
wr.study_time,
|
||||
wr.testing_time,
|
||||
wr.signed_by
|
||||
FROM
|
||||
weekly_reports wr
|
||||
INNER JOIN
|
||||
users u ON wr.user_id = u.id
|
||||
INNER JOIN
|
||||
projects p ON wr.project_id = p.id
|
||||
WHERE
|
||||
u.username = ? AND p.name = ?
|
||||
`
|
||||
|
||||
var reports []types.WeeklyReportList
|
||||
if err := d.Select(&reports, query, username, projectName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return reports, nil
|
||||
}
|
||||
|
||||
// IsProjectManager checks if a given username is a project manager for the specified project
|
||||
func (d *Db) IsProjectManager(username string, projectname string) (bool, error) {
|
||||
var manager bool
|
||||
err := d.Get(&manager, isProjectManagerQuery, username, projectname)
|
||||
return manager, err
|
||||
}
|
||||
|
||||
func (d *Db) UpdateWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error {
|
||||
query := `
|
||||
UPDATE weekly_reports
|
||||
SET
|
||||
development_time = ?,
|
||||
meeting_time = ?,
|
||||
admin_time = ?,
|
||||
own_work_time = ?,
|
||||
study_time = ?,
|
||||
testing_time = ?
|
||||
WHERE
|
||||
user_id = (SELECT id FROM users WHERE username = ?)
|
||||
AND project_id = (SELECT id FROM projects WHERE name = ?)
|
||||
AND week = ?
|
||||
`
|
||||
|
||||
_, err := d.Exec(query, developmentTime, meetingTime, adminTime, ownWorkTime, studyTime, testingTime, userName, projectName, week)
|
||||
return err
|
||||
}
|
||||
|
||||
// MigrateSampleData applies sample data to the database.
|
||||
func (d *Db) MigrateSampleData() error {
|
||||
// Insert sample data
|
||||
|
@ -440,3 +558,46 @@ func (d *Db) MigrateSampleData() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetProjectTimes retrieves a map with times per "Activity" for a given project
|
||||
func (d *Db) GetProjectTimes(projectName string) (map[string]int, error) {
|
||||
query := `
|
||||
SELECT development_time, meeting_time, admin_time, own_work_time, study_time, testing_time
|
||||
FROM weekly_reports
|
||||
JOIN projects ON weekly_reports.project_id = projects.id
|
||||
WHERE projects.name = ?
|
||||
`
|
||||
|
||||
rows, err := d.DB.Query(query, projectName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
totalTime := make(map[string]int)
|
||||
|
||||
for rows.Next() {
|
||||
var developmentTime, meetingTime, adminTime, ownWorkTime, studyTime, testingTime int
|
||||
if err := rows.Scan(&developmentTime, &meetingTime, &adminTime, &ownWorkTime, &studyTime, &testingTime); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalTime["development"] += developmentTime
|
||||
totalTime["meeting"] += meetingTime
|
||||
totalTime["admin"] += adminTime
|
||||
totalTime["own_work"] += ownWorkTime
|
||||
totalTime["study"] += studyTime
|
||||
totalTime["testing"] += testingTime
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return totalTime, nil
|
||||
}
|
||||
|
||||
func (d *Db) RemoveProject(projectname string) error {
|
||||
_, err := d.Exec("DELETE FROM projects WHERE name = ?", projectname)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Tests are not guaranteed to be sequential
|
||||
|
||||
// setupState initializes a database instance with necessary setup for testing
|
||||
func setupState() (Database, error) {
|
||||
db := DbConnect(":memory:")
|
||||
err := db.Migrate()
|
||||
|
@ -16,11 +16,62 @@ func setupState() (Database, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
// This is a more advanced setup that includes more data in the database.
|
||||
// This is useful for more complex testing scenarios.
|
||||
func setupAdvancedState() (Database, error) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add a user
|
||||
if err = db.AddUser("demouser", "password"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add a project
|
||||
if err = db.AddProject("projecttest", "description", "demouser"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Add a weekly report
|
||||
if err = db.AddWeeklyReport("projecttest", "demouser", 1, 1, 1, 1, 1, 1, 1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// TestDbConnect tests the connection to the database
|
||||
func TestDbConnect(t *testing.T) {
|
||||
db := DbConnect(":memory:")
|
||||
_ = db
|
||||
}
|
||||
|
||||
func TestSetupAdvancedState(t *testing.T) {
|
||||
db, err := setupAdvancedState()
|
||||
if err != nil {
|
||||
t.Error("setupAdvancedState failed:", err)
|
||||
}
|
||||
|
||||
// Check if the user was added
|
||||
if _, err = db.GetUserId("demouser"); err != nil {
|
||||
t.Error("GetUserId failed:", err)
|
||||
}
|
||||
|
||||
// Check if the project was added
|
||||
projects, err := db.GetAllProjects()
|
||||
if err != nil {
|
||||
t.Error("GetAllProjects failed:", err)
|
||||
}
|
||||
if len(projects) != 1 {
|
||||
t.Error("GetAllProjects failed: expected 1, got", len(projects))
|
||||
}
|
||||
|
||||
// To be continued...
|
||||
}
|
||||
|
||||
// TestDbAddUser tests the AddUser function of the database
|
||||
func TestDbAddUser(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -32,6 +83,7 @@ func TestDbAddUser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestDbGetUserId tests the GetUserID function of the database
|
||||
func TestDbGetUserId(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -52,18 +104,20 @@ func TestDbGetUserId(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestDbAddProject tests the AddProject function of the database
|
||||
func TestDbAddProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
db, err := setupAdvancedState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddProject("test", "description", "test")
|
||||
err = db.AddProject("test", "description", "demouser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDbRemoveUser tests the RemoveUser function of the database
|
||||
func TestDbRemoveUser(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -76,6 +130,7 @@ func TestDbRemoveUser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestPromoteToAdmin tests the PromoteToAdmin function of the database
|
||||
func TestPromoteToAdmin(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -93,6 +148,7 @@ func TestPromoteToAdmin(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestAddWeeklyReport tests the AddWeeklyReport function of the database
|
||||
func TestAddWeeklyReport(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -115,6 +171,7 @@ func TestAddWeeklyReport(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestAddUserToProject tests the AddUseToProject function of the database
|
||||
func TestAddUserToProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -142,6 +199,7 @@ func TestAddUserToProject(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestChangeUserRole tests the ChangeUserRole function of the database
|
||||
func TestChangeUserRole(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -158,20 +216,15 @@ func TestChangeUserRole(t *testing.T) {
|
|||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUserToProject("testuser", "testproject", "user")
|
||||
if err != nil {
|
||||
t.Error("AddUserToProject failed:", err)
|
||||
}
|
||||
|
||||
role, err := db.GetUserRole("testuser", "testproject")
|
||||
if err != nil {
|
||||
t.Error("GetUserRole failed:", err)
|
||||
}
|
||||
if role != "user" {
|
||||
t.Error("GetUserRole failed: expected user, got", role)
|
||||
if role != "project_manager" {
|
||||
t.Error("GetUserRole failed: expected project_manager, got", role)
|
||||
}
|
||||
|
||||
err = db.ChangeUserRole("testuser", "testproject", "admin")
|
||||
err = db.ChangeUserRole("testuser", "testproject", "member")
|
||||
if err != nil {
|
||||
t.Error("ChangeUserRole failed:", err)
|
||||
}
|
||||
|
@ -180,12 +233,13 @@ func TestChangeUserRole(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error("GetUserRole failed:", err)
|
||||
}
|
||||
if role != "admin" {
|
||||
t.Error("GetUserRole failed: expected admin, got", role)
|
||||
if role != "member" {
|
||||
t.Error("GetUserRole failed: expected member, got", role)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TestGetAllUsersProject tests the GetAllUsersProject function of the database
|
||||
func TestGetAllUsersProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -252,6 +306,7 @@ func TestGetAllUsersProject(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestGetAllUsersApplication tests the GetAllUsersApplicsation function of the database
|
||||
func TestGetAllUsersApplication(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -298,6 +353,7 @@ func TestGetAllUsersApplication(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestGetProjectsForUser tests the GetProjectsForUser function of the database
|
||||
func TestGetProjectsForUser(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -338,6 +394,7 @@ func TestGetProjectsForUser(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestAddProject tests AddProject function of the database
|
||||
func TestAddProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -373,6 +430,7 @@ func TestAddProject(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestGetWeeklyReport tests GetWeeklyReport function of the database
|
||||
func TestGetWeeklyReport(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -412,6 +470,48 @@ func TestGetWeeklyReport(t *testing.T) {
|
|||
// Check other fields similarly
|
||||
}
|
||||
|
||||
func TestGetUnsignedWeeklyReports(t *testing.T) {
|
||||
db, err := setupAdvancedState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUser("testuser1", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddProject("testproject", "description", "testuser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddWeeklyReport("testproject", "testuser", 1, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddWeeklyReport("testproject", "testuser1", 1, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
reports, err := db.GetUnsignedWeeklyReports("testproject")
|
||||
if err != nil {
|
||||
t.Error("GetUnsignedWeeklyReports failed:", err)
|
||||
}
|
||||
|
||||
if reports == nil {
|
||||
t.Error("Expected non-nil reports, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSignWeeklyReport tests SignWeeklyReport function of the database
|
||||
func TestSignWeeklyReport(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -464,7 +564,6 @@ func TestSignWeeklyReport(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error("GetUserId failed:", err)
|
||||
}
|
||||
fmt.Println("Project Manager's ID:", projectManagerID)
|
||||
|
||||
// Sign the report with the project manager
|
||||
err = db.SignWeeklyReport(report.ReportId, projectManagerID)
|
||||
|
@ -484,6 +583,7 @@ func TestSignWeeklyReport(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestSignWeeklyReportByAnotherProjectManager tests the scenario where a project manager attempts to sign a weekly report for a user who is not assigned to their project
|
||||
func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -502,7 +602,7 @@ func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
|||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add project
|
||||
// Add project, projectManager is the owner
|
||||
err = db.AddProject("testproject", "description", "projectManager")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
|
@ -526,17 +626,29 @@ func TestSignWeeklyReportByAnotherProjectManager(t *testing.T) {
|
|||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
anotherManagerID, err := db.GetUserId("projectManager")
|
||||
managerID, err := db.GetUserId("projectManager")
|
||||
if err != nil {
|
||||
t.Error("GetUserId failed:", err)
|
||||
}
|
||||
|
||||
err = db.SignWeeklyReport(report.ReportId, anotherManagerID)
|
||||
if err == nil {
|
||||
t.Error("Expected SignWeeklyReport to fail with a project manager who is not in the project, but it didn't")
|
||||
err = db.SignWeeklyReport(report.ReportId, managerID)
|
||||
if err != nil {
|
||||
t.Error("SignWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the report again to check if it's signed
|
||||
signedReport, err := db.GetWeeklyReport("testuser", "testproject", 1)
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Ensure the report is signed by the project manager
|
||||
if *signedReport.SignedBy != managerID {
|
||||
t.Errorf("Expected SignedBy to be %d, got %d", managerID, *signedReport.SignedBy)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetProject tests GetProject function of the database
|
||||
func TestGetProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
|
@ -566,3 +678,290 @@ func TestGetProject(t *testing.T) {
|
|||
t.Errorf("Expected Name to be testproject, got %s", project.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWeeklyReportsUser(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddProject("testproject", "description", "testuser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddWeeklyReport("testproject", "testuser", 1, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddWeeklyReport("testproject", "testuser", 2, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
reports, err := db.GetWeeklyReportsUser("testuser", "testproject")
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReportsUser failed:", err)
|
||||
}
|
||||
|
||||
// Check if the retrieved reports match the expected values
|
||||
if len(reports) != 2 {
|
||||
t.Errorf("Expected 1 report, got %d", len(reports))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsProjectManager(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Add a project manager
|
||||
err = db.AddUser("projectManager", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add a regular user
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add project
|
||||
err = db.AddProject("testproject", "description", "projectManager")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
// Add both regular users as members to the project
|
||||
err = db.AddUserToProject("testuser", "testproject", "member")
|
||||
if err != nil {
|
||||
t.Error("AddUserToProject failed:", err)
|
||||
}
|
||||
|
||||
err = db.AddUserToProject("projectManager", "testproject", "project_manager")
|
||||
if err != nil {
|
||||
t.Error("AddUserToProject failed:", err)
|
||||
}
|
||||
|
||||
// Check if the regular user is not a project manager
|
||||
isManager, err := db.IsProjectManager("testuser", "testproject")
|
||||
if err != nil {
|
||||
t.Error("IsProjectManager failed:", err)
|
||||
}
|
||||
if isManager {
|
||||
t.Error("Expected testuser not to be a project manager, but it is.")
|
||||
}
|
||||
|
||||
// Check if the project manager is indeed a project manager
|
||||
isManager, err = db.IsProjectManager("projectManager", "testproject")
|
||||
if err != nil {
|
||||
t.Error("IsProjectManager failed:", err)
|
||||
}
|
||||
if !isManager {
|
||||
t.Error("Expected projectManager to be a project manager, but it's not.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProjectTimes(t *testing.T) {
|
||||
// Initialize
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Create a user
|
||||
user := "TeaUser"
|
||||
password := "Vanilla"
|
||||
err = db.AddUser(user, password)
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Create a project
|
||||
projectName := "ProjectVanilla"
|
||||
projectDescription := "When tea tastes its best"
|
||||
err = db.AddProject(projectName, projectDescription, user) // Fix the variable name here
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Tests the func in db.go
|
||||
totalTime, err := db.GetProjectTimes(projectName)
|
||||
if err != nil {
|
||||
t.Error("GetTotalTimePerActivity failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the totalTime map is not nil
|
||||
if totalTime == nil {
|
||||
t.Error("Expected non-nil totalTime map, got nil")
|
||||
return
|
||||
}
|
||||
|
||||
// Define the expected valeus
|
||||
expectedTotalTime := map[string]int{
|
||||
"development": 0,
|
||||
"meeting": 0,
|
||||
"admin": 0,
|
||||
"own_work": 0,
|
||||
"study": 0,
|
||||
"testing": 0,
|
||||
}
|
||||
|
||||
// Compare the expectedTotalTime with the totalTime retrieved from the database
|
||||
for activity, expectedTime := range expectedTotalTime {
|
||||
if totalTime[activity] != expectedTime {
|
||||
t.Errorf("Expected %s time to be %d, got %d", activity, expectedTime, totalTime[activity])
|
||||
}
|
||||
}
|
||||
|
||||
// Insert some data into the database for different activities
|
||||
err = db.AddWeeklyReport(projectName, user, 1, 1, 3, 2, 1, 4, 5)
|
||||
if err != nil {
|
||||
t.Error("Failed to insert data into the database:", err)
|
||||
return
|
||||
}
|
||||
|
||||
newTotalTime, err := db.GetProjectTimes(projectName)
|
||||
if err != nil {
|
||||
t.Error("GetTotalTimePerActivity failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
newExpectedTotalTime := map[string]int{
|
||||
"development": 1,
|
||||
"meeting": 3,
|
||||
"admin": 2,
|
||||
"own_work": 1,
|
||||
"study": 4,
|
||||
"testing": 5,
|
||||
}
|
||||
|
||||
for activity, newExpectedTime := range newExpectedTotalTime {
|
||||
if newTotalTime[activity] != newExpectedTime {
|
||||
t.Errorf("Expected %s time to be %d, got %d", activity, newExpectedTime, newTotalTime[activity])
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestEnsureManagerOfCreatedProject(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Add a user
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add a project
|
||||
err = db.AddProject("testproject", "description", "testuser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
// Set user to a project manager
|
||||
// err = db.AddUserToProject("testuser", "testproject", "project_manager")
|
||||
// if err != nil {
|
||||
// t.Error("AddUserToProject failed:", err)
|
||||
// }
|
||||
|
||||
managerState, err := db.IsProjectManager("testuser", "testproject")
|
||||
if err != nil {
|
||||
t.Error("IsProjectManager failed:", err)
|
||||
}
|
||||
|
||||
if !managerState {
|
||||
t.Error("Expected testuser to be a project manager, but it's not.")
|
||||
}
|
||||
}
|
||||
|
||||
// TestUpdateWeeklyReport tests the UpdateWeeklyReport function of the database
|
||||
func TestUpdateWeeklyReport(t *testing.T) {
|
||||
db, err := setupState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Add a user
|
||||
err = db.AddUser("testuser", "password")
|
||||
if err != nil {
|
||||
t.Error("AddUser failed:", err)
|
||||
}
|
||||
|
||||
// Add a project
|
||||
err = db.AddProject("testproject", "description", "testuser")
|
||||
if err != nil {
|
||||
t.Error("AddProject failed:", err)
|
||||
}
|
||||
|
||||
// Add a weekly report
|
||||
err = db.AddWeeklyReport("testproject", "testuser", 1, 1, 1, 1, 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error("AddWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Update the weekly report
|
||||
err = db.UpdateWeeklyReport("testproject", "testuser", 1, 2, 2, 2, 2, 2, 2)
|
||||
if err != nil {
|
||||
t.Error("UpdateWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Retrieve the updated report
|
||||
updatedReport, err := db.GetWeeklyReport("testuser", "testproject", 1)
|
||||
if err != nil {
|
||||
t.Error("GetWeeklyReport failed:", err)
|
||||
}
|
||||
|
||||
// Check if the report was updated correctly
|
||||
if updatedReport.DevelopmentTime != 2 ||
|
||||
updatedReport.MeetingTime != 2 ||
|
||||
updatedReport.AdminTime != 2 ||
|
||||
updatedReport.OwnWorkTime != 2 ||
|
||||
updatedReport.StudyTime != 2 ||
|
||||
updatedReport.TestingTime != 2 {
|
||||
t.Error("UpdateWeeklyReport failed: report not updated correctly")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveProject(t *testing.T) {
|
||||
db, err := setupAdvancedState()
|
||||
if err != nil {
|
||||
t.Error("setupState failed:", err)
|
||||
}
|
||||
|
||||
// Promote user to Admin
|
||||
err = db.PromoteToAdmin("demouser")
|
||||
if err != nil {
|
||||
t.Error("PromoteToAdmin failed:", err)
|
||||
}
|
||||
|
||||
// Remove project
|
||||
err = db.RemoveProject("projecttest")
|
||||
if err != nil {
|
||||
t.Error("RemoveProject failed:", err)
|
||||
}
|
||||
|
||||
// Check if the project was removed
|
||||
projects, err := db.GetAllProjects()
|
||||
if err != nil {
|
||||
t.Error("GetAllProjects failed:", err)
|
||||
}
|
||||
if len(projects) != 0 {
|
||||
t.Error("RemoveProject failed: expected 0, got", len(projects))
|
||||
}
|
||||
|
||||
}
|
||||
|
17
backend/internal/database/middleware.go
Normal file
17
backend/internal/database/middleware.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package database
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
// Simple middleware that provides a shared database pool as a local key "db"
|
||||
func DbMiddleware(db *Database) func(c *fiber.Ctx) error {
|
||||
return func(c *fiber.Ctx) error {
|
||||
c.Locals("db", db)
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to get the database from the context, without fiddling with casts
|
||||
func GetDb(c *fiber.Ctx) Database {
|
||||
// Dereference a pointer to a local, casted to a pointer to a Database
|
||||
return *c.Locals("db").(*Database)
|
||||
}
|
|
@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS weekly_reports (
|
|||
study_time INTEGER,
|
||||
testing_time INTEGER,
|
||||
signed_by INTEGER,
|
||||
UNIQUE(user_id, project_id, week),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||
FOREIGN KEY (signed_by) REFERENCES users(id)
|
||||
|
|
|
@ -7,6 +7,8 @@ VALUES ("user", "123");
|
|||
INSERT OR IGNORE INTO users(username, password)
|
||||
VALUES ("user2", "123");
|
||||
|
||||
INSERT OR IGNORE INTO site_admin VALUES (1);
|
||||
|
||||
INSERT OR IGNORE INTO projects(name,description,owner_user_id)
|
||||
VALUES ("projecttest","test project", 1);
|
||||
|
||||
|
@ -33,3 +35,18 @@ VALUES (3,3,"member");
|
|||
|
||||
INSERT OR IGNORE INTO user_roles(user_id,project_id,p_role)
|
||||
VALUES (2,1,"project_manager");
|
||||
|
||||
INSERT OR IGNORE INTO weekly_reports (user_id, project_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time, signed_by)
|
||||
VALUES (2, 1, 12, 20, 10, 5, 30, 15, 10, NULL);
|
||||
|
||||
INSERT OR IGNORE INTO weekly_reports (user_id, project_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time, signed_by)
|
||||
VALUES (3, 1, 12, 20, 10, 5, 30, 15, 10, NULL);
|
||||
|
||||
INSERT OR IGNORE INTO weekly_reports (user_id, project_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time, signed_by)
|
||||
VALUES (3, 1, 14, 20, 10, 5, 30, 15, 10, NULL);
|
||||
|
||||
INSERT OR IGNORE INTO weekly_reports (user_id, project_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time, signed_by)
|
||||
VALUES (3, 2, 12, 20, 10, 5, 30, 15, 10, NULL);
|
||||
|
||||
INSERT OR IGNORE INTO weekly_reports (user_id, project_id, week, development_time, meeting_time, admin_time, own_work_time, study_time, testing_time, signed_by)
|
||||
VALUES (3, 3, 12, 20, 10, 5, 30, 15, 10, NULL);
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// The actual interface that we will use
|
||||
type GlobalState interface {
|
||||
Register(c *fiber.Ctx) error // To register a new user
|
||||
UserDelete(c *fiber.Ctx) error // To delete a user
|
||||
Login(c *fiber.Ctx) error // To get the token
|
||||
LoginRenew(c *fiber.Ctx) error // To renew the token
|
||||
CreateProject(c *fiber.Ctx) error // To create a new project
|
||||
GetUserProjects(c *fiber.Ctx) error // To get all projects
|
||||
SubmitWeeklyReport(c *fiber.Ctx) error
|
||||
GetWeeklyReport(c *fiber.Ctx) error
|
||||
SignReport(c *fiber.Ctx) error
|
||||
GetProject(c *fiber.Ctx) error
|
||||
AddUserToProjectHandler(c *fiber.Ctx) error
|
||||
PromoteToAdmin(c *fiber.Ctx) error
|
||||
// GetProject(c *fiber.Ctx) error // To get a specific project
|
||||
// UpdateProject(c *fiber.Ctx) error // To update a project
|
||||
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
||||
// CreateTask(c *fiber.Ctx) error // To create a new task
|
||||
// GetTasks(c *fiber.Ctx) error // To get all tasks
|
||||
// GetTask(c *fiber.Ctx) error // To get a specific task
|
||||
// UpdateTask(c *fiber.Ctx) error // To update a task
|
||||
// DeleteTask(c *fiber.Ctx) error // To delete a task
|
||||
// CreateCollection(c *fiber.Ctx) error // To create a new collection
|
||||
// GetCollections(c *fiber.Ctx) error // To get all collections
|
||||
// GetCollection(c *fiber.Ctx) error // To get a specific collection
|
||||
// UpdateCollection(c *fiber.Ctx) error // To update a collection
|
||||
// DeleteCollection(c *fiber.Ctx) error // To delete a collection
|
||||
// SignCollection(c *fiber.Ctx) error // To sign a collection
|
||||
ListAllUsers(c *fiber.Ctx) error // To get a list of all users in the application database
|
||||
ListAllUsersProject(c *fiber.Ctx) error // To get a list of all users for a specific project
|
||||
ProjectRoleChange(c *fiber.Ctx) error // To change a users role in a project
|
||||
}
|
||||
|
||||
// "Constructor"
|
||||
func NewGlobalState(db database.Database) GlobalState {
|
||||
return &GState{Db: db}
|
||||
}
|
||||
|
||||
// The global state, which implements all the handlers
|
||||
type GState struct {
|
||||
Db database.Database
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"ttime/internal/database"
|
||||
)
|
||||
|
||||
// The actual interface that we will use
|
||||
func TestGlobalState(t *testing.T) {
|
||||
db := database.DbConnect(":memory:")
|
||||
gs := NewGlobalState(db)
|
||||
if gs == nil {
|
||||
t.Error("NewGlobalState returned nil")
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// CreateProject is a simple handler that creates a new project
|
||||
func (gs *GState) CreateProject(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
|
||||
p := new(types.NewProject)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Get the username from the token and set it as the owner of the project
|
||||
// This is ugly but
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
owner := claims["name"].(string)
|
||||
|
||||
if err := gs.Db.AddProject(p.Name, p.Description, owner); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Project added")
|
||||
}
|
||||
|
||||
// GetUserProjects returns all projects that the user is a member of
|
||||
func (gs *GState) GetUserProjects(c *fiber.Ctx) error {
|
||||
// First we get the username from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Then dip into the database to get the projects
|
||||
projects, err := gs.Db.GetProjectsForUser(username)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return a json serialized list of projects
|
||||
return c.JSON(projects)
|
||||
}
|
||||
|
||||
// ProjectRoleChange is a handler that changes a user's role within a project
|
||||
func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the request
|
||||
username := c.Params("username")
|
||||
projectName := c.Params("projectName")
|
||||
role := c.Params("role")
|
||||
|
||||
// Change the user's role within the project in the database
|
||||
if err := gs.Db.ChangeUserRole(username, projectName, role); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return a success message
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
// GetProject retrieves a specific project by its ID
|
||||
func (gs *GState) GetProject(c *fiber.Ctx) error {
|
||||
// Extract the project ID from the request parameters or body
|
||||
projectID := c.Params("projectID")
|
||||
if projectID == "" {
|
||||
log.Info("No project ID provided")
|
||||
return c.Status(400).SendString("No project ID provided")
|
||||
}
|
||||
log.Info("Getting project with ID: ", projectID)
|
||||
|
||||
// Parse the project ID into an integer
|
||||
projectIDInt, err := strconv.Atoi(projectID)
|
||||
if err != nil {
|
||||
log.Info("Invalid project ID")
|
||||
return c.Status(400).SendString("Invalid project ID")
|
||||
}
|
||||
|
||||
// Get the project from the database by its ID
|
||||
project, err := gs.Db.GetProject(projectIDInt)
|
||||
if err != nil {
|
||||
log.Info("Error getting project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return the project as JSON
|
||||
log.Info("Returning project: ", project.Name)
|
||||
return c.JSON(project)
|
||||
}
|
||||
|
||||
func (gs *GState) ListAllUsersProject(c *fiber.Ctx) error {
|
||||
// Extract the project name from the request parameters or body
|
||||
projectName := c.Params("projectName")
|
||||
if projectName == "" {
|
||||
log.Info("No project name provided")
|
||||
return c.Status(400).SendString("No project name provided")
|
||||
}
|
||||
|
||||
// Get all users associated with the project from the database
|
||||
users, err := gs.Db.GetAllUsersProject(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting users for project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning users for project: ", projectName)
|
||||
|
||||
// Return the list of users as JSON
|
||||
return c.JSON(users)
|
||||
}
|
||||
|
||||
// AddUserToProjectHandler is a handler that adds a user to a project with a specified role
|
||||
func (gs *GState) AddUserToProjectHandler(c *fiber.Ctx) error {
|
||||
// Extract necessary parameters from the request
|
||||
var requestData struct {
|
||||
Username string `json:"username"`
|
||||
ProjectName string `json:"projectName"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
if err := c.BodyParser(&requestData); err != nil {
|
||||
log.Info("Error parsing request body:", err)
|
||||
return c.Status(400).SendString("Bad request")
|
||||
}
|
||||
|
||||
// Check if the user adding another user to the project is a site admin
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
adminUsername := claims["name"].(string)
|
||||
log.Info("Admin username from claims:", adminUsername)
|
||||
|
||||
isAdmin, err := gs.Db.IsSiteAdmin(adminUsername)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !isAdmin {
|
||||
log.Info("User is not a site admin:", adminUsername)
|
||||
return c.Status(403).SendString("User is not a site admin")
|
||||
}
|
||||
|
||||
// Add the user to the project with the specified role
|
||||
err = gs.Db.AddUserToProject(requestData.Username, requestData.ProjectName, requestData.Role)
|
||||
if err != nil {
|
||||
log.Info("Error adding user to project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return success message
|
||||
log.Info("User added to project successfully:", requestData.Username)
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func (gs *GState) SubmitWeeklyReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
report := new(types.NewWeeklyReport)
|
||||
if err := c.BodyParser(report); err != nil {
|
||||
log.Info("Error parsing weekly report")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Make sure all the fields of the report are valid
|
||||
if report.Week < 1 || report.Week > 52 {
|
||||
log.Info("Invalid week number")
|
||||
return c.Status(400).SendString("Invalid week number")
|
||||
}
|
||||
if report.DevelopmentTime < 0 || report.MeetingTime < 0 || report.AdminTime < 0 || report.OwnWorkTime < 0 || report.StudyTime < 0 || report.TestingTime < 0 {
|
||||
log.Info("Invalid time report")
|
||||
return c.Status(400).SendString("Invalid time report")
|
||||
}
|
||||
|
||||
if err := gs.Db.AddWeeklyReport(report.ProjectName, username, report.Week, report.DevelopmentTime, report.MeetingTime, report.AdminTime, report.OwnWorkTime, report.StudyTime, report.TestingTime); err != nil {
|
||||
log.Info("Error adding weekly report")
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Weekly report added")
|
||||
return c.Status(200).SendString("Time report added")
|
||||
}
|
||||
|
||||
// Handler for retrieving weekly report
|
||||
func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the request
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
log.Info("Getting weekly report for: ", username)
|
||||
|
||||
// Extract project name and week from query parameters
|
||||
projectName := c.Query("projectName")
|
||||
week := c.Query("week")
|
||||
|
||||
if projectName == "" || week == "" {
|
||||
log.Info("Missing project name or week number")
|
||||
return c.Status(400).SendString("Missing project name or week number")
|
||||
}
|
||||
|
||||
// Convert week to integer
|
||||
weekInt, err := strconv.Atoi(week)
|
||||
if err != nil {
|
||||
log.Info("Invalid week number")
|
||||
return c.Status(400).SendString("Invalid week number")
|
||||
}
|
||||
|
||||
// Call the database function to get the weekly report
|
||||
report, err := gs.Db.GetWeeklyReport(username, projectName, weekInt)
|
||||
if err != nil {
|
||||
log.Info("Error getting weekly report from db:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning weekly report")
|
||||
// Return the retrieved weekly report
|
||||
return c.JSON(report)
|
||||
}
|
||||
|
||||
type ReportId struct {
|
||||
ReportId int
|
||||
}
|
||||
|
||||
func (gs *GState) SignReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
projectManagerUsername := claims["name"].(string)
|
||||
|
||||
log.Info("Signing report for: ", projectManagerUsername)
|
||||
|
||||
// Extract report ID from the request query parameters
|
||||
// reportID := c.Query("reportId")
|
||||
rid := new(ReportId)
|
||||
if err := c.BodyParser(rid); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("Signing report for: ", rid.ReportId)
|
||||
|
||||
// Get the project manager's ID
|
||||
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
|
||||
if err != nil {
|
||||
log.Info("Failed to get project manager ID")
|
||||
return c.Status(500).SendString("Failed to get project manager ID")
|
||||
}
|
||||
log.Info("Project manager ID: ", projectManagerID)
|
||||
|
||||
// Call the database function to sign the weekly report
|
||||
err = gs.Db.SignWeeklyReport(rid.ReportId, projectManagerID)
|
||||
if err != nil {
|
||||
log.Info("Error signing weekly report:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Weekly report signed successfully")
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"time"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// Register is a simple handler that registers a new user
|
||||
//
|
||||
// @Summary Register
|
||||
// @Description Register a new user
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param NewUser body types.NewUser true "User to register"
|
||||
// @Success 200 {string} string "User added"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /register [post]
|
||||
func (gs *GState) Register(c *fiber.Ctx) error {
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
log.Warn("Error parsing body")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Adding user:", u.Username)
|
||||
if err := gs.Db.AddUser(u.Username, u.Password); err != nil {
|
||||
log.Warn("Error adding user:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User added:", u.Username)
|
||||
return c.Status(200).SendString("User added")
|
||||
}
|
||||
|
||||
// This path should obviously be protected in the future
|
||||
// UserDelete deletes a user from the database
|
||||
//
|
||||
// @Summary UserDelete
|
||||
// @Description UserDelete deletes a user from the database
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "User deleted"
|
||||
// @Failure 403 {string} string "You can only delete yourself"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Router /userdelete/{username} [delete]
|
||||
func (gs *GState) UserDelete(c *fiber.Ctx) error {
|
||||
// Read from path parameters
|
||||
username := c.Params("username")
|
||||
|
||||
// Read username from Locals
|
||||
auth_username := c.Locals("user").(*jwt.Token).Claims.(jwt.MapClaims)["name"].(string)
|
||||
|
||||
if username != auth_username {
|
||||
log.Info("User tried to delete another user")
|
||||
return c.Status(403).SendString("You can only delete yourself")
|
||||
}
|
||||
|
||||
if err := gs.Db.RemoveUser(username); err != nil {
|
||||
log.Warn("Error deleting user:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User deleted:", username)
|
||||
return c.Status(200).SendString("User deleted")
|
||||
}
|
||||
|
||||
// Login is a simple login handler that returns a JWT token
|
||||
//
|
||||
// @Summary login
|
||||
// @Description logs the user in and returns a jwt token
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Param NewUser body types.NewUser true "login info"
|
||||
// @Produce plain
|
||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /login [post]
|
||||
func (gs *GState) Login(c *fiber.Ctx) error {
|
||||
// The body type is identical to a NewUser
|
||||
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
log.Warn("Error parsing body")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Username logging in:", u.Username)
|
||||
if !gs.Db.CheckUser(u.Username, u.Password) {
|
||||
log.Info("User not found")
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
// Create the Claims
|
||||
claims := jwt.MapClaims{
|
||||
"name": u.Username,
|
||||
"admin": false,
|
||||
"exp": time.Now().Add(time.Hour * 72).Unix(),
|
||||
}
|
||||
|
||||
// Create token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
log.Info("Token created for user:", u.Username)
|
||||
|
||||
// Generate encoded token and send it as response.
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
log.Warn("Error signing token")
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
println("Successfully signed token for user:", u.Username)
|
||||
return c.JSON(types.Token{Token: t})
|
||||
}
|
||||
|
||||
// LoginRenew is a simple handler that renews the token
|
||||
//
|
||||
// @Summary LoginRenews
|
||||
// @Description renews the users token
|
||||
// @Security bererToken
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /loginerenew [post]
|
||||
func (gs *GState) LoginRenew(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
|
||||
log.Info("Renewing token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
||||
renewed := jwt.MapClaims{
|
||||
"name": claims["name"],
|
||||
"admin": claims["admin"],
|
||||
"exp": claims["exp"],
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, renewed)
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
log.Warn("Error signing token")
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||
return c.JSON(types.Token{Token: t})
|
||||
}
|
||||
|
||||
// ListAllUsers is a handler that returns a list of all users in the application database
|
||||
//
|
||||
// @Summary ListsAllUsers
|
||||
// @Description lists all users
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 {json} json "Successfully signed token for user"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /users/all [get]
|
||||
func (gs *GState) ListAllUsers(c *fiber.Ctx) error {
|
||||
// Get all users from the database
|
||||
users, err := gs.Db.GetAllUsersApplication()
|
||||
if err != nil {
|
||||
log.Info("Error getting users from db:", err) // Debug print
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning all users")
|
||||
// Return the list of users as JSON
|
||||
return c.JSON(users)
|
||||
}
|
||||
|
||||
// @Summary PromoteToAdmin
|
||||
// @Description promote chosen user to admin
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param NewUser body types.NewUser true "user info"
|
||||
// @Success 200 {json} json "Successfully prometed user"
|
||||
// @Failure 400 {string} string "bad request"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /promoteToAdmin [post]
|
||||
func (gs *GState) PromoteToAdmin(c *fiber.Ctx) error {
|
||||
// Extract the username from the request body
|
||||
var newUser types.NewUser
|
||||
if err := c.BodyParser(&newUser); err != nil {
|
||||
return c.Status(400).SendString("Bad request")
|
||||
}
|
||||
username := newUser.Username
|
||||
|
||||
log.Info("Promoting user to admin:", username) // Debug print
|
||||
|
||||
// Promote the user to a site admin in the database
|
||||
if err := gs.Db.PromoteToAdmin(username); err != nil {
|
||||
log.Info("Error promoting user to admin:", err) // Debug print
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User promoted to admin successfully:", username) // Debug print
|
||||
|
||||
// Return a success message
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
51
backend/internal/handlers/projects/AddUserToProject.go
Normal file
51
backend/internal/handlers/projects/AddUserToProject.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// AddUserToProjectHandler is a handler that adds a user to a project with a specified role
|
||||
func AddUserToProjectHandler(c *fiber.Ctx) error {
|
||||
// Extract necessary parameters from the request
|
||||
var requestData struct {
|
||||
Username string `json:"username"`
|
||||
ProjectName string `json:"projectName"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
if err := c.BodyParser(&requestData); err != nil {
|
||||
log.Info("Error parsing request body:", err)
|
||||
return c.Status(400).SendString("Bad request")
|
||||
}
|
||||
|
||||
// Check if the user adding another user to the project is a site admin
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
adminUsername := claims["name"].(string)
|
||||
log.Info("Admin username from claims:", adminUsername)
|
||||
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(adminUsername)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !isAdmin {
|
||||
log.Info("User is not a site admin:", adminUsername)
|
||||
return c.Status(403).SendString("User is not a site admin")
|
||||
}
|
||||
|
||||
// Add the user to the project with the specified role
|
||||
err = db.GetDb(c).AddUserToProject(requestData.Username, requestData.ProjectName, requestData.Role)
|
||||
if err != nil {
|
||||
log.Info("Error adding user to project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return success message
|
||||
log.Info("User added to project successfully:", requestData.Username)
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
30
backend/internal/handlers/projects/CreateProject.go
Normal file
30
backend/internal/handlers/projects/CreateProject.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// CreateProject is a simple handler that creates a new project
|
||||
func CreateProject(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
|
||||
p := new(types.NewProject)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Get the username from the token and set it as the owner of the project
|
||||
// This is ugly but
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
owner := claims["name"].(string)
|
||||
|
||||
if err := db.GetDb(c).AddProject(p.Name, p.Description, owner); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Project added")
|
||||
}
|
19
backend/internal/handlers/projects/DeleteProject.go
Normal file
19
backend/internal/handlers/projects/DeleteProject.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func DeleteProject(c *fiber.Ctx) error {
|
||||
|
||||
projectID := c.Params("projectID")
|
||||
username := c.Params("username")
|
||||
|
||||
if err := db.GetDb(c).DeleteProject(projectID, username); err != nil {
|
||||
return c.Status(500).SendString((err.Error()))
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Project deleted")
|
||||
}
|
38
backend/internal/handlers/projects/GetProject.go
Normal file
38
backend/internal/handlers/projects/GetProject.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
// GetProject retrieves a specific project by its ID
|
||||
func GetProject(c *fiber.Ctx) error {
|
||||
// Extract the project ID from the request parameters or body
|
||||
projectID := c.Params("projectID")
|
||||
if projectID == "" {
|
||||
log.Info("No project ID provided")
|
||||
return c.Status(400).SendString("No project ID provided")
|
||||
}
|
||||
log.Info("Getting project with ID: ", projectID)
|
||||
|
||||
// Parse the project ID into an integer
|
||||
projectIDInt, err := strconv.Atoi(projectID)
|
||||
if err != nil {
|
||||
log.Info("Invalid project ID")
|
||||
return c.Status(400).SendString("Invalid project ID")
|
||||
}
|
||||
|
||||
// Get the project from the database by its ID
|
||||
project, err := db.GetDb(c).GetProject(projectIDInt)
|
||||
if err != nil {
|
||||
log.Info("Error getting project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return the project as JSON
|
||||
log.Info("Returning project: ", project.Name)
|
||||
return c.JSON(project)
|
||||
}
|
63
backend/internal/handlers/projects/GetProjectTimes.go
Normal file
63
backend/internal/handlers/projects/GetProjectTimes.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func GetProjectTimesHandler(c *fiber.Ctx) error {
|
||||
// Get the username from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Get project
|
||||
projectName := c.Params("projectName")
|
||||
if projectName == "" {
|
||||
log.Info("No project name provided")
|
||||
return c.Status(400).SendString("No project name provided")
|
||||
}
|
||||
|
||||
// Get all users in the project and roles
|
||||
userProjects, err := db.GetDb(c).GetAllUsersProject(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting users in project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// If the user is member
|
||||
isMember := false
|
||||
for _, userProject := range userProjects {
|
||||
if userProject.Username == username {
|
||||
isMember = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the user is admin
|
||||
if !isMember {
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
if !isAdmin {
|
||||
log.Info("User is neither a project member nor a site admin:", username)
|
||||
return c.Status(403).SendString("User is neither a project member nor a site admin")
|
||||
}
|
||||
}
|
||||
|
||||
// Get project times
|
||||
projectTimes, err := db.GetDb(c).GetProjectTimes(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting project times:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return project times as JSON
|
||||
log.Info("Returning project times for project:", projectName)
|
||||
return c.JSON(projectTimes)
|
||||
}
|
25
backend/internal/handlers/projects/GetUserProject.go
Normal file
25
backend/internal/handlers/projects/GetUserProject.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// GetUserProjects returns all projects that the user is a member of
|
||||
func GetUserProjects(c *fiber.Ctx) error {
|
||||
// First we get the username from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Then dip into the database to get the projects
|
||||
projects, err := db.GetDb(c).GetProjectsForUser(username)
|
||||
if err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return a json serialized list of projects
|
||||
return c.JSON(projects)
|
||||
}
|
32
backend/internal/handlers/projects/IsProjectManager.go
Normal file
32
backend/internal/handlers/projects/IsProjectManager.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// IsProjectManagerHandler is a handler that checks if a user is a project manager for a given project
|
||||
func IsProjectManagerHandler(c *fiber.Ctx) error {
|
||||
// Get the username from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Extract necessary parameters from the request query string
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
log.Info("Checking if user ", username, " is a project manager for project ", projectName)
|
||||
|
||||
// Check if the user is a project manager for the specified project
|
||||
isManager, err := db.GetDb(c).IsProjectManager(username, projectName)
|
||||
if err != nil {
|
||||
log.Info("Error checking project manager status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return the result as JSON
|
||||
return c.JSON(fiber.Map{"isProjectManager": isManager})
|
||||
}
|
55
backend/internal/handlers/projects/ListAllUserProjects.go
Normal file
55
backend/internal/handlers/projects/ListAllUserProjects.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func ListAllUsersProject(c *fiber.Ctx) error {
|
||||
// Extract the project name from the request parameters or body
|
||||
projectName := c.Params("projectName")
|
||||
if projectName == "" {
|
||||
log.Info("No project name provided")
|
||||
return c.Status(400).SendString("No project name provided")
|
||||
}
|
||||
|
||||
// Get the user token
|
||||
userToken := c.Locals("user").(*jwt.Token)
|
||||
claims := userToken.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Check if the user is a project manager for the specified project
|
||||
isManager, err := db.GetDb(c).IsProjectManager(username, projectName)
|
||||
if err != nil {
|
||||
log.Info("Error checking project manager status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// If the user is not a project manager, check if the user is a site admin
|
||||
if !isManager {
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
if !isAdmin {
|
||||
log.Info("User is neither a project manager nor a site admin:", username)
|
||||
return c.Status(403).SendString("User is neither a project manager nor a site admin")
|
||||
}
|
||||
}
|
||||
|
||||
// Get all users associated with the project from the database
|
||||
users, err := db.GetDb(c).GetAllUsersProject(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting users for project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning users for project: ", projectName)
|
||||
|
||||
// Return the list of users as JSON
|
||||
return c.JSON(users)
|
||||
}
|
45
backend/internal/handlers/projects/ProjectRoleChange.go
Normal file
45
backend/internal/handlers/projects/ProjectRoleChange.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// ProjectRoleChange is a handler that changes a user's role within a project
|
||||
func ProjectRoleChange(c *fiber.Ctx) error {
|
||||
|
||||
//check token and get username of current user
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Extract the necessary parameters from the request
|
||||
data := new(types.RoleChange)
|
||||
if err := c.BodyParser(data); err != nil {
|
||||
log.Info("error parsing username, project or role")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Changing role for user: ", username, " in project: ", data.Projectname, " to: ", data.Role)
|
||||
|
||||
// Dubble diping and checcking if current user is
|
||||
if ismanager, err := db.GetDb(c).IsProjectManager(username, data.Projectname); err != nil {
|
||||
log.Warn("Error checking if projectmanager:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
} else if !ismanager {
|
||||
log.Warn("User is not projectmanager")
|
||||
return c.Status(401).SendString("User is not projectmanager")
|
||||
}
|
||||
|
||||
// Change the user's role within the project in the database
|
||||
if err := db.GetDb(c).ChangeUserRole(username, data.Projectname, data.Role); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return a success message
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
35
backend/internal/handlers/projects/RemoveProject.go
Normal file
35
backend/internal/handlers/projects/RemoveProject.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package projects
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func RemoveProject(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Check if the user is a site admin
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !isAdmin {
|
||||
log.Info("User is not a site admin:", username)
|
||||
return c.Status(403).SendString("User is not a site admin")
|
||||
}
|
||||
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
if err := db.GetDb(c).RemoveProject(projectName); err != nil {
|
||||
return c.Status(500).SendString((err.Error()))
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Project deleted")
|
||||
}
|
45
backend/internal/handlers/reports/GetUnsignedReports.go
Normal file
45
backend/internal/handlers/reports/GetUnsignedReports.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func GetUnsignedReports(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
projectManagerUsername := claims["name"].(string)
|
||||
|
||||
// Extract project name and week from query parameters
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
log.Info("Getting unsigned reports for")
|
||||
|
||||
if projectName == "" {
|
||||
log.Info("Missing project name")
|
||||
return c.Status(400).SendString("Missing project name")
|
||||
}
|
||||
|
||||
// Get the project manager's ID
|
||||
isProjectManager, err := db.GetDb(c).IsProjectManager(projectManagerUsername, projectName)
|
||||
if err != nil {
|
||||
log.Info("Failed to get project manager ID")
|
||||
return c.Status(500).SendString("Failed to get project manager ID")
|
||||
}
|
||||
log.Info("User is Project Manager: ", isProjectManager)
|
||||
|
||||
// Call the database function to get the unsigned weekly reports
|
||||
reports, err := db.GetDb(c).GetUnsignedWeeklyReports(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting unsigned weekly reports:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning unsigned reports")
|
||||
// Return the list of unsigned reports
|
||||
return c.JSON(reports)
|
||||
}
|
47
backend/internal/handlers/reports/GetWeeklyReport.go
Normal file
47
backend/internal/handlers/reports/GetWeeklyReport.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// Handler for retrieving weekly report
|
||||
func GetWeeklyReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the request
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
log.Info("Getting weekly report for: ", username)
|
||||
|
||||
// Extract project name and week from query parameters
|
||||
projectName := c.Query("projectName")
|
||||
week := c.Query("week")
|
||||
|
||||
if projectName == "" || week == "" {
|
||||
log.Info("Missing project name or week number")
|
||||
return c.Status(400).SendString("Missing project name or week number")
|
||||
}
|
||||
|
||||
// Convert week to integer
|
||||
weekInt, err := strconv.Atoi(week)
|
||||
if err != nil {
|
||||
log.Info("Invalid week number")
|
||||
return c.Status(400).SendString("Invalid week number")
|
||||
}
|
||||
|
||||
// Call the database function to get the weekly report
|
||||
report, err := db.GetDb(c).GetWeeklyReport(username, projectName, weekInt)
|
||||
if err != nil {
|
||||
log.Info("Error getting weekly report from db:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning weekly report")
|
||||
// Return the retrieved weekly report
|
||||
return c.JSON(report)
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// GetWeeklyReportsUserHandler retrieves all weekly reports for a user in a specific project
|
||||
func GetWeeklyReportsUserHandler(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Extract necessary (path) parameters from the request
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
// TODO: Here we need to check whether the user is a member of the project
|
||||
// If not, we should return an error. On the other hand, if the user not a member,
|
||||
// the returned list of reports will (should) allways be empty.
|
||||
|
||||
// Retrieve weekly reports for the user in the project from the database
|
||||
reports, err := db.GetDb(c).GetWeeklyReportsUser(username, projectName)
|
||||
if err != nil {
|
||||
log.Error("Error getting weekly reports for user:", username, "in project:", projectName, ":", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning weekly reports for user:", username, "in project:", projectName)
|
||||
|
||||
// Return the list of reports as JSON
|
||||
return c.JSON(reports)
|
||||
}
|
41
backend/internal/handlers/reports/SignReport.go
Normal file
41
backend/internal/handlers/reports/SignReport.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func SignReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
projectManagerUsername := claims["name"].(string)
|
||||
|
||||
// Extract report ID from the path
|
||||
reportId, err := strconv.Atoi(c.Params("reportId"))
|
||||
if err != nil {
|
||||
log.Info("Invalid report ID")
|
||||
return c.Status(400).SendString("Invalid report ID")
|
||||
}
|
||||
|
||||
// Get the project manager's ID
|
||||
projectManagerID, err := db.GetDb(c).GetUserId(projectManagerUsername)
|
||||
if err != nil {
|
||||
log.Info("Failed to get project manager ID for user: ", projectManagerUsername)
|
||||
return c.Status(500).SendString("Failed to get project manager ID")
|
||||
}
|
||||
|
||||
// Call the database function to sign the weekly report
|
||||
err = db.GetDb(c).SignWeeklyReport(reportId, projectManagerID)
|
||||
if err != nil {
|
||||
log.Info("Error signing weekly report:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Project manager ID: ", projectManagerID, " signed report ID: ", reportId)
|
||||
return c.Status(200).SendString("Weekly report signed successfully")
|
||||
}
|
41
backend/internal/handlers/reports/SubmitWeeklyReport.go
Normal file
41
backend/internal/handlers/reports/SubmitWeeklyReport.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func SubmitWeeklyReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
report := new(types.NewWeeklyReport)
|
||||
if err := c.BodyParser(report); err != nil {
|
||||
log.Info("Error parsing weekly report")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Make sure all the fields of the report are valid
|
||||
if report.Week < 1 || report.Week > 52 {
|
||||
log.Info("Invalid week number")
|
||||
return c.Status(400).SendString("Invalid week number")
|
||||
}
|
||||
if report.DevelopmentTime < 0 || report.MeetingTime < 0 || report.AdminTime < 0 || report.OwnWorkTime < 0 || report.StudyTime < 0 || report.TestingTime < 0 {
|
||||
log.Info("Invalid time report")
|
||||
return c.Status(400).SendString("Invalid time report")
|
||||
}
|
||||
|
||||
if err := db.GetDb(c).AddWeeklyReport(report.ProjectName, username, report.Week, report.DevelopmentTime, report.MeetingTime, report.AdminTime, report.OwnWorkTime, report.StudyTime, report.TestingTime); err != nil {
|
||||
log.Info("Error adding weekly report to db:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Weekly report added")
|
||||
return c.Status(200).SendString("Time report added")
|
||||
}
|
44
backend/internal/handlers/reports/UpdateWeeklyReport.go
Normal file
44
backend/internal/handlers/reports/UpdateWeeklyReport.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package reports
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func UpdateWeeklyReport(c *fiber.Ctx) error {
|
||||
// Extract the necessary parameters from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Parse the request body into an UpdateWeeklyReport struct
|
||||
var updateReport types.UpdateWeeklyReport
|
||||
if err := c.BodyParser(&updateReport); err != nil {
|
||||
log.Info("Error parsing weekly report")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Make sure all the fields of the report are valid
|
||||
if updateReport.Week < 1 || updateReport.Week > 52 {
|
||||
log.Info("Invalid week number")
|
||||
return c.Status(400).SendString("Invalid week number")
|
||||
}
|
||||
|
||||
if updateReport.DevelopmentTime < 0 || updateReport.MeetingTime < 0 || updateReport.AdminTime < 0 || updateReport.OwnWorkTime < 0 || updateReport.StudyTime < 0 || updateReport.TestingTime < 0 {
|
||||
log.Info("Invalid time report")
|
||||
return c.Status(400).SendString("Invalid time report")
|
||||
}
|
||||
|
||||
// Update the weekly report in the database
|
||||
if err := db.GetDb(c).UpdateWeeklyReport(updateReport.ProjectName, username, updateReport.Week, updateReport.DevelopmentTime, updateReport.MeetingTime, updateReport.AdminTime, updateReport.OwnWorkTime, updateReport.StudyTime, updateReport.TestingTime); err != nil {
|
||||
log.Info("Error updating weekly report in db:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Weekly report updated")
|
||||
return c.Status(200).SendString("Weekly report updated")
|
||||
}
|
44
backend/internal/handlers/users/ChangeUserName.go
Normal file
44
backend/internal/handlers/users/ChangeUserName.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// ChangeUserName changes a user's username in the database
|
||||
func ChangeUserName(c *fiber.Ctx) error {
|
||||
// Check token and get username of current user
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
adminUsername := claims["name"].(string)
|
||||
log.Info(adminUsername)
|
||||
|
||||
// Extract the necessary parameters from the request
|
||||
data := new(types.StrNameChange)
|
||||
if err := c.BodyParser(data); err != nil {
|
||||
log.Info("Error parsing username")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Check if the current user is an admin
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(adminUsername)
|
||||
if err != nil {
|
||||
log.Warn("Error checking if admin:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
} else if !isAdmin {
|
||||
log.Warn("Tried changing name when not admin")
|
||||
return c.Status(401).SendString("You cannot change name unless you are an admin")
|
||||
}
|
||||
|
||||
// Change the user's name in the database
|
||||
if err := db.GetDb(c).ChangeUserName(data.PrevName, data.NewName); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return a success message
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
22
backend/internal/handlers/users/GetUsersProjects.go
Normal file
22
backend/internal/handlers/users/GetUsersProjects.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
func GetAllUsersProject(c *fiber.Ctx) error {
|
||||
// Get all users from a project
|
||||
projectName := c.Params("projectName")
|
||||
users, err := db.GetDb(c).GetAllUsersProject(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting users from project:", err) // Debug print
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning all users")
|
||||
// Return the list of users as JSON
|
||||
return c.JSON(users)
|
||||
}
|
31
backend/internal/handlers/users/ListAllUsers.go
Normal file
31
backend/internal/handlers/users/ListAllUsers.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
// ListAllUsers is a handler that returns a list of all users in the application database
|
||||
// @Summary ListsAllUsers
|
||||
// @Description lists all users
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 {json} json "Successfully signed token for user"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /users/all [get]
|
||||
func ListAllUsers(c *fiber.Ctx) error {
|
||||
// Get all users from the database
|
||||
users, err := db.GetDb(c).GetAllUsersApplication()
|
||||
if err != nil {
|
||||
log.Info("Error getting users from db:", err) // Debug print
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Returning all users")
|
||||
// Return the list of users as JSON
|
||||
return c.JSON(users)
|
||||
}
|
65
backend/internal/handlers/users/Login.go
Normal file
65
backend/internal/handlers/users/Login.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
"time"
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// Login is a simple login handler that returns a JWT token
|
||||
// @Summary login
|
||||
// @Description logs the user in and returns a jwt token
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Param NewUser body types.NewUser true "login info"
|
||||
// @Produce plain
|
||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /login [post]
|
||||
func Login(c *fiber.Ctx) error {
|
||||
// The body type is identical to a NewUser
|
||||
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
log.Warn("Error parsing body")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Username logging in:", u.Username)
|
||||
if !db.GetDb(c).CheckUser(u.Username, u.Password) {
|
||||
log.Info("User not found")
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
isAdmin, err := db.GetDb(c).IsSiteAdmin(u.Username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
// Create the Claims
|
||||
claims := jwt.MapClaims{
|
||||
"name": u.Username,
|
||||
"admin": isAdmin,
|
||||
"exp": time.Now().Add(time.Hour * 72).Unix(),
|
||||
}
|
||||
|
||||
// Create token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
log.Info("Token created for user:", u.Username)
|
||||
|
||||
// Generate encoded token and send it as response.
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
log.Warn("Error signing token")
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
println("Successfully signed token for user:", u.Username)
|
||||
return c.JSON(types.Token{Token: t})
|
||||
}
|
44
backend/internal/handlers/users/LoginRenew.go
Normal file
44
backend/internal/handlers/users/LoginRenew.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
"time"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// LoginRenew is a simple handler that renews the token
|
||||
// @Summary LoginRenews
|
||||
// @Description renews the users token
|
||||
// @Security bererToken
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 Token types.Token "Successfully signed token for user"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /loginerenew [post]
|
||||
func LoginRenew(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
|
||||
log.Info("Renewing token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
||||
renewed := jwt.MapClaims{
|
||||
"name": claims["name"],
|
||||
"admin": claims["admin"],
|
||||
"exp": claims["exp"],
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, renewed)
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
log.Warn("Error signing token")
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
log.Info("Successfully renewed token for user:", user.Claims.(jwt.MapClaims)["name"])
|
||||
return c.JSON(types.Token{Token: t})
|
||||
}
|
42
backend/internal/handlers/users/PromoteToAdmin.go
Normal file
42
backend/internal/handlers/users/PromoteToAdmin.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
// @Summary PromoteToAdmin
|
||||
// @Description promote chosen user to admin
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param NewUser body types.NewUser true "user info"
|
||||
// @Success 200 {json} json "Successfully promoted user"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /promoteToAdmin [post]
|
||||
func PromoteToAdmin(c *fiber.Ctx) error {
|
||||
// Extract the username from the request body
|
||||
var newUser types.NewUser
|
||||
if err := c.BodyParser(&newUser); err != nil {
|
||||
return c.Status(400).SendString("Bad request")
|
||||
}
|
||||
username := newUser.Username
|
||||
|
||||
log.Info("Promoting user to admin:", username) // Debug print
|
||||
|
||||
// Promote the user to a site admin in the database
|
||||
if err := db.GetDb(c).PromoteToAdmin(username); err != nil {
|
||||
log.Info("Error promoting user to admin:", err) // Debug print
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User promoted to admin successfully:", username) // Debug print
|
||||
|
||||
// Return a success message
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
38
backend/internal/handlers/users/Register.go
Normal file
38
backend/internal/handlers/users/Register.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
"ttime/internal/types"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
// Register is a simple handler that registers a new user
|
||||
//
|
||||
// @Summary Register
|
||||
// @Description Register a new user
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Param NewUser body types.NewUser true "User to register"
|
||||
// @Success 200 {string} string "User added"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /register [post]
|
||||
func Register(c *fiber.Ctx) error {
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
log.Warn("Error parsing body")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("Adding user:", u.Username)
|
||||
if err := db.GetDb(c).AddUser(u.Username, u.Password); err != nil {
|
||||
log.Warn("Error adding user:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User added:", u.Username)
|
||||
return c.Status(200).SendString("User added")
|
||||
}
|
43
backend/internal/handlers/users/UserDelete.go
Normal file
43
backend/internal/handlers/users/UserDelete.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package users
|
||||
|
||||
import (
|
||||
db "ttime/internal/database"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// This path should obviously be protected in the future
|
||||
// UserDelete deletes a user from the database
|
||||
//
|
||||
// @Summary UserDelete
|
||||
// @Description UserDelete deletes a user from the database
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce plain
|
||||
// @Success 200 {string} string "User deleted"
|
||||
// @Failure 403 {string} string "You can only delete yourself"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Failure 401 {string} string "Unauthorized"
|
||||
// @Router /userdelete/{username} [delete]
|
||||
func UserDelete(c *fiber.Ctx) error {
|
||||
// Read from path parameters
|
||||
username := c.Params("username")
|
||||
|
||||
// Read username from Locals
|
||||
auth_username := c.Locals("user").(*jwt.Token).Claims.(jwt.MapClaims)["name"].(string)
|
||||
|
||||
if username == auth_username {
|
||||
log.Info("User tried to delete itself")
|
||||
return c.Status(403).SendString("You can't delete yourself")
|
||||
}
|
||||
|
||||
if err := db.GetDb(c).RemoveUser(username); err != nil {
|
||||
log.Warn("Error deleting user:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
log.Info("User deleted:", username)
|
||||
return c.Status(200).SendString("User deleted")
|
||||
}
|
|
@ -20,6 +20,27 @@ type NewWeeklyReport struct {
|
|||
TestingTime int `json:"testingTime"`
|
||||
}
|
||||
|
||||
type WeeklyReportList struct {
|
||||
// The name of the project, as it appears in the database
|
||||
ProjectName string `json:"projectName" db:"project_name"`
|
||||
// The week number
|
||||
Week int `json:"week" db:"week"`
|
||||
// Total time spent on development
|
||||
DevelopmentTime int `json:"developmentTime" db:"development_time"`
|
||||
// Total time spent in meetings
|
||||
MeetingTime int `json:"meetingTime" db:"meeting_time"`
|
||||
// Total time spent on administrative tasks
|
||||
AdminTime int `json:"adminTime" db:"admin_time"`
|
||||
// Total time spent on personal projects
|
||||
OwnWorkTime int `json:"ownWorkTime" db:"own_work_time"`
|
||||
// Total time spent on studying
|
||||
StudyTime int `json:"studyTime" db:"study_time"`
|
||||
// Total time spent on testing
|
||||
TestingTime int `json:"testingTime" db:"testing_time"`
|
||||
// The project manager who signed it
|
||||
SignedBy *int `json:"signedBy" db:"signed_by"`
|
||||
}
|
||||
|
||||
type WeeklyReport struct {
|
||||
// The ID of the report
|
||||
ReportId int `json:"reportId" db:"report_id"`
|
||||
|
@ -44,3 +65,24 @@ type WeeklyReport struct {
|
|||
// The project manager who signed it
|
||||
SignedBy *int `json:"signedBy" db:"signed_by"`
|
||||
}
|
||||
|
||||
type UpdateWeeklyReport struct {
|
||||
// The name of the project, as it appears in the database
|
||||
ProjectName string `json:"projectName"`
|
||||
// The name of the user
|
||||
UserName string `json:"userName"`
|
||||
// The week number
|
||||
Week int `json:"week"`
|
||||
// Total time spent on development
|
||||
DevelopmentTime int `json:"developmentTime"`
|
||||
// Total time spent in meetings
|
||||
MeetingTime int `json:"meetingTime"`
|
||||
// Total time spent on administrative tasks
|
||||
AdminTime int `json:"adminTime"`
|
||||
// Total time spent on personal projects
|
||||
OwnWorkTime int `json:"ownWorkTime"`
|
||||
// Total time spent on studying
|
||||
StudyTime int `json:"studyTime"`
|
||||
// Total time spent on testing
|
||||
TestingTime int `json:"testingTime"`
|
||||
}
|
||||
|
|
|
@ -13,3 +13,17 @@ type NewProject struct {
|
|||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Used to change the role of a user in a project.
|
||||
// If name is identical to the name contained in the token, the role can be changed.
|
||||
// If the name is different, only a project manager can change the role.
|
||||
type RoleChange struct {
|
||||
UserName string `json:"username"`
|
||||
Role string `json:"role" tstype:"'project_manager' | 'user'"`
|
||||
Projectname string `json:"projectname"`
|
||||
}
|
||||
|
||||
type NameChange struct {
|
||||
ID int `json:"id" db:"id"`
|
||||
Name string `json:"name" db:"name"`
|
||||
}
|
||||
|
|
|
@ -32,3 +32,8 @@ type PublicUser struct {
|
|||
type Token struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type StrNameChange struct {
|
||||
PrevName string `json:"prevName" db:"prevName"`
|
||||
NewName string `json:"newName" db:"newName"`
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
_ "ttime/docs"
|
||||
"ttime/internal/config"
|
||||
"ttime/internal/database"
|
||||
"ttime/internal/handlers"
|
||||
"ttime/internal/handlers/projects"
|
||||
"ttime/internal/handlers/reports"
|
||||
"ttime/internal/handlers/users"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -33,6 +35,12 @@ import (
|
|||
// @externalDocs.description OpenAPI
|
||||
// @externalDocs.url https://swagger.io/resources/open-api/
|
||||
|
||||
/**
|
||||
Main function for starting the server and initializing configurations.
|
||||
Reads configuration from file, pretty prints it, connects to the database,
|
||||
migrates it, and sets up routes for the server.
|
||||
*/
|
||||
|
||||
func main() {
|
||||
conf, err := config.ReadConfigFromFile("config.toml")
|
||||
if err != nil {
|
||||
|
@ -48,24 +56,28 @@ func main() {
|
|||
|
||||
// Connect to the database
|
||||
db := database.DbConnect(conf.DbPath)
|
||||
|
||||
// Migrate the database
|
||||
if err = db.Migrate(); err != nil {
|
||||
fmt.Println("Error migrating database: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Migrate sample data, should not be used in production
|
||||
if err = db.MigrateSampleData(); err != nil {
|
||||
fmt.Println("Error migrating sample data: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Get our global state
|
||||
gs := handlers.NewGlobalState(db)
|
||||
// Create the server
|
||||
server := fiber.New()
|
||||
|
||||
// We want some logs
|
||||
server.Use(logger.New())
|
||||
|
||||
// Sets up db middleware, accessed as Local "db" key
|
||||
server.Use(database.DbMiddleware(&db))
|
||||
|
||||
// Mounts the swagger documentation, this is available at /swagger/index.html
|
||||
server.Get("/swagger/*", swagger.HandlerDefault)
|
||||
|
||||
|
@ -73,27 +85,51 @@ func main() {
|
|||
// This will likely be replaced by an embedded filesystem in the future
|
||||
server.Static("/", "./static")
|
||||
|
||||
// Register our unprotected routes
|
||||
server.Post("/api/register", gs.Register)
|
||||
server.Post("/api/login", gs.Login)
|
||||
// Create a group for our API
|
||||
api := server.Group("/api")
|
||||
|
||||
// Every route from here on will require a valid JWT
|
||||
// Register our unprotected routes
|
||||
api.Post("/register", users.Register)
|
||||
api.Post("/login", users.Login)
|
||||
|
||||
// Every route from here on will require a valid
|
||||
// JWT bearer token authentication in the header
|
||||
server.Use(jwtware.New(jwtware.Config{
|
||||
SigningKey: jwtware.SigningKey{Key: []byte("secret")},
|
||||
}))
|
||||
|
||||
// Protected routes (require a valid JWT bearer token authentication header)
|
||||
server.Post("/api/submitWeeklyReport", gs.SubmitWeeklyReport)
|
||||
server.Get("/api/getUserProjects", gs.GetUserProjects)
|
||||
server.Post("/api/loginrenew", gs.LoginRenew)
|
||||
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
||||
server.Post("/api/project", gs.CreateProject)
|
||||
server.Get("/api/project/:projectId", gs.GetProject)
|
||||
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||
server.Post("/api/signReport", gs.SignReport)
|
||||
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
||||
server.Get("/api/users/all", gs.ListAllUsers)
|
||||
// All user related routes
|
||||
// userGroup := api.Group("/user") // Not currently in use
|
||||
api.Get("/users/all", users.ListAllUsers)
|
||||
api.Get("/project/getAllUsers", users.GetAllUsersProject)
|
||||
api.Post("/login", users.Login)
|
||||
api.Post("/register", users.Register)
|
||||
api.Post("/loginrenew", users.LoginRenew)
|
||||
api.Post("/promoteToAdmin", users.PromoteToAdmin)
|
||||
api.Put("/changeUserName", users.ChangeUserName)
|
||||
api.Delete("/userdelete/:username", users.UserDelete) // Perhaps just use POST to avoid headaches
|
||||
|
||||
// All project related routes
|
||||
// projectGroup := api.Group("/project") // Not currently in use
|
||||
api.Get("/getUserProjects", projects.GetUserProjects)
|
||||
api.Get("/project/:projectId", projects.GetProject)
|
||||
api.Get("/checkIfProjectManager/:projectName", projects.IsProjectManagerHandler)
|
||||
api.Get("/getUsersProject/:projectName", projects.ListAllUsersProject)
|
||||
api.Post("/project", projects.CreateProject)
|
||||
api.Post("/ProjectRoleChange", projects.ProjectRoleChange)
|
||||
api.Delete("/removeProject/:projectName", projects.RemoveProject)
|
||||
api.Delete("/project/:projectID", projects.DeleteProject)
|
||||
|
||||
// All report related routes
|
||||
// reportGroup := api.Group("/report") // Not currently in use
|
||||
api.Get("/getWeeklyReport", reports.GetWeeklyReport)
|
||||
api.Get("/getUnsignedReports/:projectName", reports.GetUnsignedReports)
|
||||
api.Get("/getWeeklyReportsUser/:projectName", reports.GetWeeklyReportsUserHandler)
|
||||
api.Post("/submitWeeklyReport", reports.SubmitWeeklyReport)
|
||||
api.Put("/signReport/:reportId", reports.SignReport)
|
||||
api.Put("/addUserToProject", projects.AddUserToProjectHandler)
|
||||
api.Put("/updateWeeklyReport", reports.UpdateWeeklyReport)
|
||||
|
||||
// Announce the port we are listening on and start the server
|
||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||
if err != nil {
|
||||
|
|
|
@ -13,7 +13,6 @@ FROM docker.io/golang:alpine as go
|
|||
RUN apk add gcompat
|
||||
RUN apk add gcc
|
||||
RUN apk add musl-dev
|
||||
RUN apk add make
|
||||
RUN apk add sqlite
|
||||
WORKDIR /build
|
||||
ADD backend/go.mod backend/go.sum ./
|
||||
|
@ -24,9 +23,7 @@ RUN go mod download
|
|||
# Add the source code
|
||||
ADD backend .
|
||||
|
||||
RUN make migrate
|
||||
|
||||
# RUN go build -o server
|
||||
RUN go build -o server
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./main.go
|
||||
|
||||
# Strip the binary for a smaller image
|
||||
|
@ -37,6 +34,7 @@ FROM docker.io/alpine:latest as runner
|
|||
RUN adduser -D nonroot
|
||||
RUN addgroup nonroot nonroot
|
||||
WORKDIR /app
|
||||
RUN chown nonroot:nonroot /app
|
||||
|
||||
# Copy the frontend SPA build into public
|
||||
COPY --from=client /build/dist static
|
||||
|
@ -44,9 +42,6 @@ COPY --from=client /build/dist static
|
|||
# Copy the server binary
|
||||
COPY --from=go /build/server server
|
||||
|
||||
# Copy the database
|
||||
COPY --from=go /build/db.sqlite3 db.sqlite3
|
||||
|
||||
# Expose port 8080
|
||||
EXPOSE 8080
|
||||
|
||||
|
|
|
@ -4,50 +4,167 @@ import {
|
|||
User,
|
||||
Project,
|
||||
NewProject,
|
||||
UserProjectMember,
|
||||
WeeklyReport,
|
||||
StrNameChange,
|
||||
NewProjMember,
|
||||
} from "../Types/goTypes";
|
||||
|
||||
// This type of pattern should be hard to misuse
|
||||
/**
|
||||
* Response object returned by API methods.
|
||||
*/
|
||||
export interface APIResponse<T> {
|
||||
/** Indicates whether the API call was successful */
|
||||
success: boolean;
|
||||
/** Optional message providing additional information or error description */
|
||||
message?: string;
|
||||
/** Optional data returned by the API method */
|
||||
data?: T;
|
||||
}
|
||||
|
||||
// Note that all protected routes also require a token
|
||||
// Defines all the methods that an instance of the API must implement
|
||||
/**
|
||||
* Interface defining methods that an instance of the API must implement.
|
||||
*/
|
||||
interface API {
|
||||
/** Register a new user */
|
||||
/**
|
||||
* Register a new user
|
||||
* @param {NewUser} user The user object to be registered
|
||||
* @returns {Promise<APIResponse<User>>} A promise containing the API response with the user data.
|
||||
*/
|
||||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
||||
/** Remove a user */
|
||||
|
||||
/**
|
||||
* Removes a user.
|
||||
* @param {string} username The username of the user to be removed.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<User>>} A promise containing the API response with the removed user data.
|
||||
*/
|
||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
||||
/** Login */
|
||||
|
||||
/**
|
||||
* Check if user is project manager.
|
||||
* @param {string} username The username of the user.
|
||||
* @param {string} projectName The name of the project.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<boolean>>} A promise containing the API response indicating if the user is a project manager.
|
||||
*/
|
||||
checkIfProjectManager(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>>;
|
||||
|
||||
/** Logs in a user with the provided credentials.
|
||||
* @param {NewUser} NewUser The user object containing username and password.
|
||||
* @returns {Promise<APIResponse<string>>} A promise resolving to an API response with a token.
|
||||
*/
|
||||
login(NewUser: NewUser): Promise<APIResponse<string>>;
|
||||
/** Renew the token */
|
||||
|
||||
/**
|
||||
* Renew the token
|
||||
* @param {string} token The current authentication token.
|
||||
* @returns {Promise<APIResponse<string>>} A promise resolving to an API response with a renewed token.
|
||||
*/
|
||||
renewToken(token: string): Promise<APIResponse<string>>;
|
||||
/** Create a project */
|
||||
|
||||
/** Promote user to admin */
|
||||
|
||||
/** Creates a new project.
|
||||
* @param {NewProject} project The project object containing name and description.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response with the created project.
|
||||
*/
|
||||
createProject(
|
||||
project: NewProject,
|
||||
token: string,
|
||||
): Promise<APIResponse<Project>>;
|
||||
/** Submit a weekly report */
|
||||
|
||||
/** Submits a weekly report
|
||||
* @param {NewWeeklyReport} weeklyReport The weekly report object.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<NewWeeklyReport>>} A promise resolving to an API response with the submitted report.
|
||||
*/
|
||||
submitWeeklyReport(
|
||||
project: NewWeeklyReport,
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/**Gets a weekly report*/
|
||||
): Promise<APIResponse<string>>;
|
||||
|
||||
/** Gets a weekly report for a specific user, project and week
|
||||
* @param {string} projectName The name of the project.
|
||||
* @param {string} week The week number.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<WeeklyReport>>} A promise resolving to an API response with the retrieved report.
|
||||
*/
|
||||
getWeeklyReport(
|
||||
username: string,
|
||||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/** Gets all the projects of a user*/
|
||||
): Promise<APIResponse<WeeklyReport>>;
|
||||
|
||||
/**
|
||||
* Returns all the weekly reports for a user in a particular project
|
||||
* The username is derived from the token
|
||||
* @param {string} projectName The name of the project
|
||||
* @param {string} token The token of the user
|
||||
* @returns {APIResponse<WeeklyReport[]>} A list of weekly reports
|
||||
*/
|
||||
getWeeklyReportsForUser(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>>;
|
||||
|
||||
/** Gets all the projects of a user
|
||||
* @param {string} token - The authentication token.
|
||||
* @returns {Promise<APIResponse<Project[]>>} A promise containing the API response with the user's projects.
|
||||
*/
|
||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
|
||||
/** Gets a project by its id.
|
||||
* @param {number} id The id of the project to retrieve.
|
||||
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response containing the project data.
|
||||
*/
|
||||
getProject(id: number): Promise<APIResponse<Project>>;
|
||||
|
||||
/** Gets a list of all users.
|
||||
* @param {string} token The authentication token of the requesting user.
|
||||
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
||||
*/
|
||||
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
||||
/** Gets all users in a project from name*/
|
||||
getAllUsersProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<UserProjectMember[]>>;
|
||||
/**
|
||||
* Changes the username of a user in the database.
|
||||
* @param {StrNameChange} data The object containing the previous and new username.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<void>>} A promise resolving to an API response.
|
||||
*/
|
||||
changeUserName(
|
||||
data: StrNameChange,
|
||||
token: string,
|
||||
): Promise<APIResponse<void>>;
|
||||
addUserToProject(
|
||||
user: NewProjMember,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewProjMember>>;
|
||||
|
||||
removeProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>>;
|
||||
|
||||
/**
|
||||
* Signs a report. Keep in mind that the user which the token belongs to must be
|
||||
* the project manager of the project the report belongs to.
|
||||
*
|
||||
* @param {number} reportId The id of the report to sign
|
||||
* @param {string} token The authentication token
|
||||
*/
|
||||
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
|
||||
}
|
||||
|
||||
// Export an instance of the API
|
||||
/** An instance of the API */
|
||||
export const api: API = {
|
||||
async registerUser(user: NewUser): Promise<APIResponse<User>> {
|
||||
try {
|
||||
|
@ -81,26 +198,54 @@ export const api: API = {
|
|||
token: string,
|
||||
): Promise<APIResponse<User>> {
|
||||
try {
|
||||
const response = await fetch("/api/userdelete", {
|
||||
method: "POST",
|
||||
const response = await fetch(`/api/userdelete/${username}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(username),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to remove user" };
|
||||
return { success: false, message: "Could not remove user" };
|
||||
} else {
|
||||
const data = (await response.json()) as User;
|
||||
return { success: true, data };
|
||||
return { success: true };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to remove user" };
|
||||
}
|
||||
},
|
||||
|
||||
async checkIfProjectManager(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/checkIfProjectManager/${projectName}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to check if project manager",
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as boolean;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to check if project manager" };
|
||||
}
|
||||
},
|
||||
|
||||
async createProject(
|
||||
project: NewProject,
|
||||
token: string,
|
||||
|
@ -126,6 +271,30 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async addUserToProject(
|
||||
user: NewProjMember,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewProjMember>> {
|
||||
try {
|
||||
const response = await fetch("/api/addUserToProject", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(user),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to add member" };
|
||||
} else {
|
||||
return { success: true, message: "Added member" };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to add member" };
|
||||
}
|
||||
},
|
||||
|
||||
async renewToken(token: string): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/loginrenew", {
|
||||
|
@ -177,7 +346,7 @@ export const api: API = {
|
|||
async submitWeeklyReport(
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/submitWeeklyReport", {
|
||||
method: "POST",
|
||||
|
@ -195,8 +364,8 @@ export const api: API = {
|
|||
};
|
||||
}
|
||||
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
return { success: true, data };
|
||||
const data = await response.text();
|
||||
return { success: true, message: data };
|
||||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
|
@ -206,29 +375,62 @@ export const api: API = {
|
|||
},
|
||||
|
||||
async getWeeklyReport(
|
||||
username: string,
|
||||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
): Promise<APIResponse<WeeklyReport>> {
|
||||
try {
|
||||
const response = await fetch("/api/getWeeklyReport", {
|
||||
const response = await fetch(
|
||||
`/api/getWeeklyReport?projectName=${projectName}&week=${week}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
} else {
|
||||
const data = (await response.json()) as WeeklyReport;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
}
|
||||
},
|
||||
|
||||
async getWeeklyReportsForUser(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>> {
|
||||
try {
|
||||
const response = await fetch(`/api/getWeeklyReportsUser/${projectName}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ username, projectName, week }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
return {
|
||||
success: false,
|
||||
message:
|
||||
"Failed to get weekly reports for project: Response code " +
|
||||
response.status,
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
const data = (await response.json()) as WeeklyReport[];
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to get weekly report" };
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get weekly reports for project, unknown error",
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -253,7 +455,6 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
// Gets a projet by id, currently untested since we have no javascript-based tests
|
||||
async getProject(id: number): Promise<APIResponse<Project>> {
|
||||
try {
|
||||
const response = await fetch(`/api/project/${id}`, {
|
||||
|
@ -278,4 +479,138 @@ export const api: API = {
|
|||
};
|
||||
}
|
||||
},
|
||||
|
||||
async getAllUsers(token: string): Promise<APIResponse<string[]>> {
|
||||
try {
|
||||
const response = await fetch("/api/users/all", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "Failed to get users",
|
||||
});
|
||||
} else {
|
||||
const data = (await response.json()) as string[];
|
||||
return Promise.resolve({ success: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "API is not ok",
|
||||
});
|
||||
}
|
||||
},
|
||||
//Gets all users in a project
|
||||
async getAllUsersProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<UserProjectMember[]>> {
|
||||
try {
|
||||
const response = await fetch(`/api/getUsersProject/${projectName}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "Failed to get users",
|
||||
});
|
||||
} else {
|
||||
const data = (await response.json()) as UserProjectMember[];
|
||||
return Promise.resolve({ success: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "API is not ok",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async changeUserName(
|
||||
data: StrNameChange,
|
||||
token: string,
|
||||
): Promise<APIResponse<void>> {
|
||||
try {
|
||||
const response = await fetch("/api/changeUserName", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to change username" };
|
||||
} else {
|
||||
return { success: true };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to change username" };
|
||||
}
|
||||
},
|
||||
|
||||
async removeProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch(`/api/projectdelete/${projectName}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "Failed to remove project",
|
||||
});
|
||||
} else {
|
||||
const data = await response.text();
|
||||
return Promise.resolve({ success: true, message: data });
|
||||
}
|
||||
} catch (e) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "Failed to remove project",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async signReport(
|
||||
reportId: number,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch(`/api/signReport/${reportId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to sign report" };
|
||||
} else {
|
||||
return { success: true, message: "Report signed" };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to sign report" };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
39
frontend/src/Components/AddMember.tsx
Normal file
39
frontend/src/Components/AddMember.tsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { APIResponse, api } from "../API/API";
|
||||
import { NewProjMember } from "../Types/goTypes";
|
||||
|
||||
/**
|
||||
* Tries to add a member to a project
|
||||
* @param {Object} props - A NewProjMember
|
||||
* @returns {boolean} True if added, false if not
|
||||
*/
|
||||
function AddMember(props: { memberToAdd: NewProjMember }): boolean {
|
||||
let added = false;
|
||||
if (
|
||||
props.memberToAdd.username === "" ||
|
||||
props.memberToAdd.role === "" ||
|
||||
props.memberToAdd.projectname === ""
|
||||
) {
|
||||
alert("All fields must be filled before adding");
|
||||
return added;
|
||||
}
|
||||
api
|
||||
.addUserToProject(
|
||||
props.memberToAdd,
|
||||
localStorage.getItem("accessToken") ?? "",
|
||||
)
|
||||
.then((response: APIResponse<NewProjMember>) => {
|
||||
if (response.success) {
|
||||
alert("Member added");
|
||||
added = true;
|
||||
} else {
|
||||
alert("Member not added");
|
||||
console.error(response.message);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("An error occurred during member add:", error);
|
||||
});
|
||||
return added;
|
||||
}
|
||||
|
||||
export default AddMember;
|
|
@ -7,7 +7,7 @@ import Button from "./Button";
|
|||
|
||||
/**
|
||||
* Tries to add a project to the system
|
||||
* @param props - Project name and description
|
||||
* @param {Object} props - Project name and description
|
||||
* @returns {boolean} True if created, false if not
|
||||
*/
|
||||
function CreateProject(props: { name: string; description: string }): boolean {
|
||||
|
@ -34,8 +34,8 @@ function CreateProject(props: { name: string; description: string }): boolean {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to add a project to the system
|
||||
* @returns {JSX.Element} UI for project adding
|
||||
* Provides UI for adding a project to the system.
|
||||
* @returns {JSX.Element} - Returns the component UI for adding a project
|
||||
*/
|
||||
function AddProject(): JSX.Element {
|
||||
const [name, setName] = useState("");
|
||||
|
|
92
frontend/src/Components/AddUserToProject.tsx
Normal file
92
frontend/src/Components/AddUserToProject.tsx
Normal file
|
@ -0,0 +1,92 @@
|
|||
import { useState } from "react";
|
||||
import { NewProjMember } from "../Types/goTypes";
|
||||
import Button from "./Button";
|
||||
import GetAllUsers from "./GetAllUsers";
|
||||
import AddMember from "./AddMember";
|
||||
import BackButton from "./BackButton";
|
||||
|
||||
/**
|
||||
* Provides UI for adding a member to a project.
|
||||
* @returns {JSX.Element} - Returns the component UI for adding a member
|
||||
*/
|
||||
function AddUserToProject(): JSX.Element {
|
||||
const [name, setName] = useState("");
|
||||
const [users, setUsers] = useState<string[]>([]);
|
||||
const [role, setRole] = useState("");
|
||||
GetAllUsers({ setUsersProp: setUsers });
|
||||
|
||||
const handleClick = (): boolean => {
|
||||
const newMember: NewProjMember = {
|
||||
username: name,
|
||||
projectname: localStorage.getItem("projectName") ?? "",
|
||||
role: role,
|
||||
};
|
||||
return AddMember({ memberToAdd: newMember });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center rounded-3xl content-center pl-20 pr-20 h-[75vh] w-[50vh]">
|
||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
||||
User chosen: [{name}]
|
||||
</p>
|
||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
||||
Role chosen: [{role}]
|
||||
</p>
|
||||
<p className="pb-4 mb-2 text-center font-bold text-[18px]">
|
||||
Project chosen: [{localStorage.getItem("projectName") ?? ""}]
|
||||
</p>
|
||||
<p className="p-1">Choose role:</p>
|
||||
<div className="border-2 border-black p-2 rounded-xl text-center h-[10h] w-[16vh]">
|
||||
<ul className="text-center items-center font-medium space-y-2">
|
||||
<li
|
||||
className="h-[10h] w-[14vh] items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||
onClick={() => {
|
||||
setRole("member");
|
||||
}}
|
||||
>
|
||||
{"Member"}
|
||||
</li>
|
||||
<li
|
||||
className="h-[10h] w-[14vh] items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||
onClick={() => {
|
||||
setRole("project_manager");
|
||||
}}
|
||||
>
|
||||
{"Project manager"}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p className="p-1">Choose user:</p>
|
||||
<div className="border-2 border-black p-2 rounded-xl text-center overflow-scroll h-[26vh] w-[26vh]">
|
||||
<ul className="text-center font-medium space-y-2">
|
||||
<div></div>
|
||||
{users.map((user) => (
|
||||
<li
|
||||
className="items-start p-1 border-2 border-black rounded-full bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||
key={user}
|
||||
value={user}
|
||||
onClick={() => {
|
||||
setName(user);
|
||||
}}
|
||||
>
|
||||
<span>{user}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="flex space-x-5 items-center justify-between">
|
||||
<Button
|
||||
text="Add"
|
||||
onClick={(): void => {
|
||||
handleClick();
|
||||
}}
|
||||
type="submit"
|
||||
/>
|
||||
<BackButton />
|
||||
</div>
|
||||
<p className="text-center text-gray-500 text-xs"></p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddUserToProject;
|
|
@ -1,74 +1,36 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { NewWeeklyReport } from "../Types/goTypes";
|
||||
//Info: This component is used to display all the time reports for a project. It will display the week number,
|
||||
//total time spent, and if the report has been signed or not. The user can click on a report to edit it.
|
||||
import { useEffect, useState } from "react";
|
||||
import { WeeklyReport } from "../Types/goTypes";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Renders a component that displays all the time reports for a specific project.
|
||||
* @returns {JSX.Element} representing the component.
|
||||
*/
|
||||
function AllTimeReportsInProject(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
||||
|
||||
/* const getWeeklyReports = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getWeeklyReports(token);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setWeeklyReports(response.data ?? []);
|
||||
} else {
|
||||
console.error(response.message);
|
||||
}
|
||||
}; */
|
||||
|
||||
const getWeeklyReports = async (): Promise<void> => {
|
||||
const report: NewWeeklyReport[] = [
|
||||
{
|
||||
projectName: projectName ?? "",
|
||||
week: 10,
|
||||
developmentTime: 1,
|
||||
meetingTime: 1,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 1,
|
||||
studyTime: 1,
|
||||
testingTime: 1,
|
||||
},
|
||||
{
|
||||
projectName: projectName ?? "",
|
||||
week: 11,
|
||||
developmentTime: 1,
|
||||
meetingTime: 1,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 100,
|
||||
studyTime: 1,
|
||||
testingTime: 1,
|
||||
},
|
||||
{
|
||||
projectName: projectName ?? "",
|
||||
week: 12,
|
||||
developmentTime: 1,
|
||||
meetingTime: 1,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 1,
|
||||
studyTime: 1,
|
||||
testingTime: 1000,
|
||||
},
|
||||
{
|
||||
projectName: projectName ?? "",
|
||||
week: 20,
|
||||
developmentTime: 1,
|
||||
meetingTime: 1,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 1,
|
||||
studyTime: 1,
|
||||
testingTime: 10000,
|
||||
},
|
||||
// Add more reports as needed
|
||||
];
|
||||
setWeeklyReports(report);
|
||||
await Promise.resolve();
|
||||
};
|
||||
const [weeklyReports, setWeeklyReports] = useState<WeeklyReport[]>([]);
|
||||
|
||||
// Call getProjects when the component mounts
|
||||
useEffect(() => {
|
||||
const getWeeklyReports = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getWeeklyReportsForUser(
|
||||
projectName ?? "",
|
||||
token,
|
||||
);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setWeeklyReports(response.data ?? []);
|
||||
} else {
|
||||
console.error(response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void getWeeklyReports();
|
||||
}, []);
|
||||
}, [projectName]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -96,7 +58,7 @@ function AllTimeReportsInProject(): JSX.Element {
|
|||
</h1>
|
||||
<h1>
|
||||
<span className="font-bold">{"Signed: "}</span>
|
||||
YES
|
||||
{newWeeklyReport.signedBy ? "YES" : "NO"}
|
||||
</h1>
|
||||
</div>
|
||||
</Link>
|
||||
|
|
103
frontend/src/Components/AllTimeReportsInProjectOtherUser.tsx
Normal file
103
frontend/src/Components/AllTimeReportsInProjectOtherUser.tsx
Normal file
|
@ -0,0 +1,103 @@
|
|||
//Info: This component is used to display all the time reports for a project. It will display the week number,
|
||||
//total time spent, and if the report has been signed or not. The user can click on a report to edit it.
|
||||
import { useEffect, useState } from "react";
|
||||
import { NewWeeklyReport } from "../Types/goTypes";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders a component that displays all the time reports for a specific project.
|
||||
* @returns {JSX.Element} representing the component.
|
||||
*/
|
||||
function AllTimeReportsInProject(): JSX.Element {
|
||||
const { username } = useParams();
|
||||
const { projectName } = useParams();
|
||||
const [weeklyReports, setWeeklyReports] = useState<NewWeeklyReport[]>([]);
|
||||
|
||||
/* // Call getProjects when the component mounts
|
||||
useEffect(() => {
|
||||
const getWeeklyReports = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getWeeklyReportsForUser(
|
||||
projectName ?? "",
|
||||
token,
|
||||
);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setWeeklyReports(response.data ?? []);
|
||||
} else {
|
||||
console.error(response.message);
|
||||
}
|
||||
}; */
|
||||
// Mock data
|
||||
const getWeeklyReports = async (): Promise<void> => {
|
||||
// Simulate a delay
|
||||
await Promise.resolve();
|
||||
const mockWeeklyReports: NewWeeklyReport[] = [
|
||||
{
|
||||
projectName: "Project 1",
|
||||
week: 1,
|
||||
developmentTime: 10,
|
||||
meetingTime: 2,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 3,
|
||||
studyTime: 4,
|
||||
testingTime: 5,
|
||||
},
|
||||
{
|
||||
projectName: "Project 1",
|
||||
week: 2,
|
||||
developmentTime: 8,
|
||||
meetingTime: 2,
|
||||
adminTime: 1,
|
||||
ownWorkTime: 3,
|
||||
studyTime: 4,
|
||||
testingTime: 5,
|
||||
},
|
||||
// Add more reports as needed
|
||||
];
|
||||
|
||||
// Use the mock data instead of the real data
|
||||
setWeeklyReports(mockWeeklyReports);
|
||||
};
|
||||
useEffect(() => {
|
||||
void getWeeklyReports();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-[30px] font-bold">{username}'s Time Reports</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[30px]">
|
||||
{weeklyReports.map((newWeeklyReport, index) => (
|
||||
<Link
|
||||
to={`/editOthersTR/${projectName}/${username}/${newWeeklyReport.week}`}
|
||||
key={index}
|
||||
className="border-b-2 border-black w-full"
|
||||
>
|
||||
<div className="flex justify-between">
|
||||
<h1>
|
||||
<span className="font-bold">{"Week: "}</span>
|
||||
{newWeeklyReport.week}
|
||||
</h1>
|
||||
<h1>
|
||||
<span className="font-bold">{"Total Time: "}</span>
|
||||
{newWeeklyReport.developmentTime +
|
||||
newWeeklyReport.meetingTime +
|
||||
newWeeklyReport.adminTime +
|
||||
newWeeklyReport.ownWorkTime +
|
||||
newWeeklyReport.studyTime +
|
||||
newWeeklyReport.testingTime}{" "}
|
||||
min
|
||||
</h1>
|
||||
<h1>
|
||||
<span className="font-bold">{"Signed: "}</span>
|
||||
NO
|
||||
</h1>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default AllTimeReportsInProject;
|
18
frontend/src/Components/AuthorizedRoute.tsx
Normal file
18
frontend/src/Components/AuthorizedRoute.tsx
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Navigate } from "react-router-dom";
|
||||
import React from "react";
|
||||
|
||||
interface AuthorizedRouteProps {
|
||||
children: React.ReactNode;
|
||||
isAuthorized: boolean;
|
||||
}
|
||||
|
||||
export function AuthorizedRoute({
|
||||
children,
|
||||
isAuthorized,
|
||||
}: AuthorizedRouteProps): JSX.Element {
|
||||
if (!isAuthorized) {
|
||||
return <Navigate to="/unauthorized" />;
|
||||
}
|
||||
|
||||
return children as React.ReactElement;
|
||||
}
|
|
@ -1,5 +1,11 @@
|
|||
//info: Back button component to navigate back to the previous page
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders a back button component.
|
||||
*
|
||||
* @returns The JSX element representing the back button.
|
||||
*/
|
||||
function BackButton(): JSX.Element {
|
||||
const navigate = useNavigate();
|
||||
const goBack = (): void => {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
//info: Background animation component to animate the background of loginpage
|
||||
import { useEffect } from "react";
|
||||
|
||||
/**
|
||||
* Renders a background animation component.
|
||||
* This component pre-loads images and starts a background transition animation.
|
||||
*/
|
||||
const BackgroundAnimation = (): JSX.Element => {
|
||||
useEffect(() => {
|
||||
const images = [
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
//info: Basic window component to display content and buttons of a page, inclduing header and footer
|
||||
//content to insert is placed in the content prop, and buttons in the buttons prop
|
||||
import Header from "./Header";
|
||||
import Footer from "./Footer";
|
||||
|
||||
/**
|
||||
* Renders a basic window component with a header, content, and footer.
|
||||
*
|
||||
* @param {Object} props - The component props.
|
||||
* @param {React.ReactNode} props.content - The content to be rendered in the window.
|
||||
* @param {React.ReactNode} props.buttons - The buttons to be rendered in the footer.
|
||||
* @returns {JSX.Element} The rendered basic window component.
|
||||
*/
|
||||
function BasicWindow({
|
||||
content,
|
||||
buttons,
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
/**
|
||||
* Button component to display a button with text and onClick function.
|
||||
*
|
||||
* @param {Object} props - The component props.
|
||||
* @param {string} props.text - The text to display on the button.
|
||||
* @param {Function} props.onClick - The function to run when the button is clicked.
|
||||
* @param {"submit" | "button" | "reset"} props.type - The type of button.
|
||||
* @returns {JSX.Element} The rendered Button component.
|
||||
*/
|
||||
function Button({
|
||||
text,
|
||||
onClick,
|
||||
|
|
83
frontend/src/Components/ChangeRoles.tsx
Normal file
83
frontend/src/Components/ChangeRoles.tsx
Normal file
|
@ -0,0 +1,83 @@
|
|||
import { useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import Button from "./Button";
|
||||
|
||||
export default function ChangeRoles(): JSX.Element {
|
||||
const [selectedRole, setSelectedRole] = useState("");
|
||||
const { username } = useParams();
|
||||
|
||||
const handleRoleChange = (
|
||||
event: React.ChangeEvent<HTMLInputElement>,
|
||||
): void => {
|
||||
setSelectedRole(event.target.value);
|
||||
};
|
||||
|
||||
// const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
// event.preventDefault();
|
||||
|
||||
// const response = await api.changeRole(username, selectedRole, token);
|
||||
// if (response.success) {
|
||||
// console.log("Role changed successfully");
|
||||
// } else {
|
||||
// console.error("Failed to change role:", response.message);
|
||||
// }
|
||||
// };
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
Change roll for: {username}
|
||||
</h1>
|
||||
<form
|
||||
className="text-[20px] font-bold border-4 border-black bg-white flex flex-col items-center justify-center min-h-[50vh] h-fit w-[30vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]"
|
||||
onSubmit={undefined}
|
||||
>
|
||||
<div className="self-start">
|
||||
<div>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
value="System Manager"
|
||||
checked={selectedRole === "System Manager"}
|
||||
onChange={handleRoleChange}
|
||||
className="ml-2 mr-2 mb-6"
|
||||
/>
|
||||
System Manager
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
value="Developer"
|
||||
checked={selectedRole === "Developer"}
|
||||
onChange={handleRoleChange}
|
||||
className="ml-2 mr-2 mb-6"
|
||||
/>
|
||||
Developer
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
value="Tester"
|
||||
checked={selectedRole === "Tester"}
|
||||
onChange={handleRoleChange}
|
||||
className="ml-2 mr-2 mb-6"
|
||||
/>
|
||||
Tester
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
text="Save"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="submit"
|
||||
/>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
import React, { useState } from "react";
|
||||
import { api } from "../API/API";
|
||||
import InputField from "./InputField";
|
||||
import BackButton from "./BackButton";
|
||||
import Button from "./Button";
|
||||
|
||||
import { api } from "../API/API";
|
||||
|
||||
function ChangeUsername(): JSX.Element {
|
||||
const [newUsername, setNewUsername] = useState("");
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
setNewUsername(e.target.value);
|
||||
|
@ -14,15 +12,38 @@ function ChangeUsername(): JSX.Element {
|
|||
|
||||
const handleSubmit = async (): Promise<void> => {
|
||||
try {
|
||||
// Call the API function to update the username
|
||||
await api.updateUsername(newUsername);
|
||||
// Optionally, add a success message or redirect the user
|
||||
// Call the API function to change the username
|
||||
const token = localStorage.getItem("accessToken");
|
||||
if (!token) {
|
||||
throw new Error("Access token not found");
|
||||
}
|
||||
|
||||
const response = await api.changeUserName(
|
||||
{ prevName: "currentName", newName: newUsername },
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
// Optionally, add a success message or redirect the user
|
||||
console.log("Username changed successfully");
|
||||
} else {
|
||||
// Handle the error message
|
||||
console.error("Failed to change username:", response.message);
|
||||
setErrorMessage(response.message ?? "Failed to change username");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating username:", error);
|
||||
console.error("Error changing username:", error);
|
||||
// Optionally, handle the error
|
||||
setErrorMessage("Failed to change username");
|
||||
}
|
||||
};
|
||||
|
||||
const handleButtonClick = (): void => {
|
||||
handleSubmit().catch((error) => {
|
||||
console.error("Error in handleSubmit:", error);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<InputField
|
||||
|
@ -31,6 +52,8 @@ function ChangeUsername(): JSX.Element {
|
|||
value={newUsername}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
{errorMessage && <div>{errorMessage}</div>}
|
||||
<button onClick={handleButtonClick}>Update Username</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import { useState, useEffect } from "react";
|
||||
|
||||
// Interface for the response from the server
|
||||
// This should eventually reside in a dedicated file
|
||||
interface CountResponse {
|
||||
pressCount: number;
|
||||
}
|
||||
|
||||
// Some constants for the button
|
||||
const BUTTON_ENDPOINT = "/api/button";
|
||||
|
||||
// A simple button that counts how many times it's been pressed
|
||||
export function CountButton(): JSX.Element {
|
||||
const [count, setCount] = useState<number>(NaN);
|
||||
|
||||
// useEffect with a [] dependency array runs only once
|
||||
useEffect(() => {
|
||||
async function getCount(): Promise<void> {
|
||||
const response = await fetch(BUTTON_ENDPOINT);
|
||||
const data = (await response.json()) as CountResponse;
|
||||
setCount(data.pressCount);
|
||||
}
|
||||
void getCount();
|
||||
}, []);
|
||||
|
||||
// This is what runs on every button click
|
||||
function press(): void {
|
||||
async function pressPost(): Promise<void> {
|
||||
const response = await fetch(BUTTON_ENDPOINT, { method: "POST" });
|
||||
const data = (await response.json()) as CountResponse;
|
||||
setCount(data.pressCount);
|
||||
}
|
||||
void pressPost();
|
||||
}
|
||||
|
||||
// Return some JSX with the button and associated handler
|
||||
return <button onClick={press}>count is {count}</button>;
|
||||
}
|
|
@ -11,7 +11,6 @@ import { api, APIResponse } from "../API/API";
|
|||
*/
|
||||
|
||||
function DeleteUser(props: { usernameToDelete: string }): boolean {
|
||||
//console.log(props.usernameToDelete); FOR DEBUG
|
||||
let removed = false;
|
||||
api
|
||||
.removeUser(
|
||||
|
@ -20,12 +19,16 @@ function DeleteUser(props: { usernameToDelete: string }): boolean {
|
|||
)
|
||||
.then((response: APIResponse<User>) => {
|
||||
if (response.success) {
|
||||
alert("User has been deleted!");
|
||||
location.reload();
|
||||
removed = true;
|
||||
} else {
|
||||
alert("User has not been deleted");
|
||||
console.error(response.message);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
alert("User has not been deleted");
|
||||
console.error("An error occurred during creation:", error);
|
||||
});
|
||||
return removed;
|
||||
|
|
129
frontend/src/Components/DisplayUnsignedReports.tsx
Normal file
129
frontend/src/Components/DisplayUnsignedReports.tsx
Normal file
|
@ -0,0 +1,129 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
|
||||
interface UnsignedReports {
|
||||
projectName: string;
|
||||
username: string;
|
||||
week: number;
|
||||
signed: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a component that displays the projects a user is a part of and links to the projects start-page.
|
||||
* @returns The JSX element representing the component.
|
||||
*/
|
||||
function DisplayUserProject(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
const [unsignedReports, setUnsignedReports] = useState<UnsignedReports[]>([]);
|
||||
//const navigate = useNavigate();
|
||||
|
||||
// const getUnsignedReports = async (): Promise<void> => {
|
||||
// const token = localStorage.getItem("accessToken") ?? "";
|
||||
// const response = await api.getUserProjects(token);
|
||||
// console.log(response);
|
||||
// if (response.success) {
|
||||
// setUnsignedReports(response.data ?? []);
|
||||
// } else {
|
||||
// console.error(response.message);
|
||||
// }
|
||||
// };
|
||||
|
||||
// const handleReportClick = async (projectName: string): Promise<void> => {
|
||||
// const username = localStorage.getItem("username") ?? "";
|
||||
// const token = localStorage.getItem("accessToken") ?? "";
|
||||
// const response = await api.checkIfProjectManager(
|
||||
// username,
|
||||
// projectName,
|
||||
// token,
|
||||
// );
|
||||
// if (response.success) {
|
||||
// if (response.data) {
|
||||
// navigate(`/PMProjectPage/${projectName}`);
|
||||
// } else {
|
||||
// navigate(`/project/${projectName}`);
|
||||
// }
|
||||
// } else {
|
||||
// // handle error
|
||||
// console.error(response.message);
|
||||
// }
|
||||
// };
|
||||
|
||||
const getUnsignedReports = async (): Promise<void> => {
|
||||
// Simulate a delay
|
||||
await Promise.resolve();
|
||||
|
||||
// Use mock data
|
||||
const reports: UnsignedReports[] = [
|
||||
{
|
||||
projectName: "projecttest",
|
||||
username: "user1",
|
||||
week: 2,
|
||||
signed: false,
|
||||
},
|
||||
{
|
||||
projectName: "projecttest",
|
||||
username: "user2",
|
||||
week: 2,
|
||||
signed: false,
|
||||
},
|
||||
{
|
||||
projectName: "projecttest",
|
||||
username: "user3",
|
||||
week: 2,
|
||||
signed: false,
|
||||
},
|
||||
{
|
||||
projectName: "projecttest",
|
||||
username: "user4",
|
||||
week: 2,
|
||||
signed: false,
|
||||
},
|
||||
];
|
||||
|
||||
// Set the state with the mock data
|
||||
setUnsignedReports(reports);
|
||||
};
|
||||
|
||||
// Call getProjects when the component mounts
|
||||
useEffect(() => {
|
||||
void getUnsignedReports();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
All Unsigned Reports In: {projectName}{" "}
|
||||
</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[70vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[20px]">
|
||||
{unsignedReports.map(
|
||||
(unsignedReport: UnsignedReports, index: number) => (
|
||||
<h1 key={index} className="border-b-2 border-black w-full">
|
||||
<div className="flex justify-between">
|
||||
<div className="flex">
|
||||
<h1>{unsignedReport.username}</h1>
|
||||
<span className="ml-6 mr-2 font-bold">Week:</span>
|
||||
<h1>{unsignedReport.week}</h1>
|
||||
<span className="ml-6 mr-2 font-bold">Signed:</span>
|
||||
<h1>NO</h1>
|
||||
</div>
|
||||
<div className="flex">
|
||||
<div className="ml-auto flex space-x-4">
|
||||
<Link
|
||||
to={`/PMViewUnsignedReport/${projectName}/${unsignedReport.username}/${unsignedReport.week}`}
|
||||
>
|
||||
<h1 className="underline cursor-pointer font-bold">
|
||||
View Report
|
||||
</h1>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</h1>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default DisplayUserProject;
|
65
frontend/src/Components/DisplayUserProjects.tsx
Normal file
65
frontend/src/Components/DisplayUserProjects.tsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { Project } from "../Types/goTypes";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Renders a component that displays the projects a user is a part of and links to the projects start-page.
|
||||
* @returns The JSX element representing the component.
|
||||
*/
|
||||
function DisplayUserProject(): JSX.Element {
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const getProjects = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getUserProjects(token);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setProjects(response.data ?? []);
|
||||
} else {
|
||||
console.error(response.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleProjectClick = async (projectName: string): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.checkIfProjectManager(projectName, token);
|
||||
console.log(response.data);
|
||||
if (response.success) {
|
||||
if (response.data === true) {
|
||||
navigate(`/PMProjectPage/${projectName}`);
|
||||
} else {
|
||||
navigate(`/project/${projectName}`);
|
||||
}
|
||||
} else {
|
||||
// handle error
|
||||
console.error(response.message);
|
||||
}
|
||||
};
|
||||
|
||||
// Call getProjects when the component mounts
|
||||
useEffect(() => {
|
||||
void getProjects();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">Your Projects</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||
{projects.map((project) => (
|
||||
<div
|
||||
onClick={() => void handleProjectClick(project.name)}
|
||||
key={project.id}
|
||||
>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
{project.name}
|
||||
</h1>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default DisplayUserProject;
|
|
@ -1,9 +1,13 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { NewWeeklyReport } from "../Types/goTypes";
|
||||
import { WeeklyReport, NewWeeklyReport } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import Button from "./Button";
|
||||
|
||||
/**
|
||||
* Renders the component for editing a weekly report.
|
||||
* @returns JSX.Element
|
||||
*/
|
||||
export default function GetWeeklyReport(): JSX.Element {
|
||||
const [week, setWeek] = useState(0);
|
||||
const [developmentTime, setDevelopmentTime] = useState(0);
|
||||
|
@ -14,45 +18,47 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
const [testingTime, setTestingTime] = useState(0);
|
||||
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const username = localStorage.getItem("username") ?? "";
|
||||
const { projectName } = useParams();
|
||||
const { fetchedWeek } = useParams();
|
||||
|
||||
const fetchWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
username,
|
||||
projectName ?? "",
|
||||
fetchedWeek?.toString() ?? "0",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: NewWeeklyReport = response.data ?? {
|
||||
projectName: "",
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
const { projectName, fetchedWeek } = useParams<{
|
||||
projectName: string;
|
||||
fetchedWeek: string;
|
||||
}>();
|
||||
console.log(projectName, fetchedWeek);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
projectName ?? "",
|
||||
fetchedWeek ?? "",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: WeeklyReport = response.data ?? {
|
||||
reportId: 0,
|
||||
userId: 0,
|
||||
projectId: 0,
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchWeeklyReport();
|
||||
});
|
||||
}, [projectName, fetchedWeek, token]);
|
||||
|
||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||
const newWeeklyReport: NewWeeklyReport = {
|
||||
|
@ -73,6 +79,7 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">Edit Time Report</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
|
@ -87,24 +94,10 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
}}
|
||||
>
|
||||
<div className="flex flex-col items-center">
|
||||
<input
|
||||
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
||||
type="week"
|
||||
placeholder="Week"
|
||||
value={
|
||||
week === 0 ? "" : `2024-W${week.toString().padStart(2, "0")}`
|
||||
}
|
||||
onChange={(e) => {
|
||||
const weekNumber = parseInt(e.target.value.split("-W")[1]);
|
||||
setWeek(weekNumber);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
onPaste={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
<div className="flex flex-col w-1/2 border-b-2 border-black items-center justify-center">
|
||||
<h1 className="font-bold text-[30px]"> Week: {week}</h1>
|
||||
</div>
|
||||
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -124,9 +117,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={developmentTime}
|
||||
value={developmentTime === 0 ? "" : developmentTime}
|
||||
onChange={(e) => {
|
||||
setDevelopmentTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setDevelopmentTime(0);
|
||||
return;
|
||||
} else {
|
||||
setDevelopmentTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -143,9 +141,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={meetingTime}
|
||||
value={meetingTime === 0 ? "" : meetingTime}
|
||||
onChange={(e) => {
|
||||
setMeetingTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setMeetingTime(0);
|
||||
return;
|
||||
} else {
|
||||
setMeetingTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -162,9 +165,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={adminTime}
|
||||
value={adminTime === 0 ? "" : adminTime}
|
||||
onChange={(e) => {
|
||||
setAdminTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setAdminTime(0);
|
||||
return;
|
||||
} else {
|
||||
setAdminTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -181,9 +189,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={ownWorkTime}
|
||||
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||
onChange={(e) => {
|
||||
setOwnWorkTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setOwnWorkTime(0);
|
||||
return;
|
||||
} else {
|
||||
setOwnWorkTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -200,9 +213,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={studyTime}
|
||||
value={studyTime === 0 ? "" : studyTime}
|
||||
onChange={(e) => {
|
||||
setStudyTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setStudyTime(0);
|
||||
return;
|
||||
} else {
|
||||
setStudyTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -219,9 +237,14 @@ export default function GetWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={testingTime}
|
||||
value={testingTime === 0 ? "" : testingTime}
|
||||
onChange={(e) => {
|
||||
setTestingTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setTestingTime(0);
|
||||
return;
|
||||
} else {
|
||||
setTestingTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
//info: Footer component to display the footer of a page where the buttons are placed
|
||||
import React from "react";
|
||||
|
||||
/**
|
||||
* Footer component.
|
||||
*
|
||||
* @param {Object} props - The component props.
|
||||
* @param {React.ReactNode} props.children - The children elements to render inside the footer (buttons).
|
||||
* @returns {JSX.Element} The rendered footer component.
|
||||
*/
|
||||
function Footer({ children }: { children: React.ReactNode }): JSX.Element {
|
||||
return (
|
||||
<footer className="bg-white">
|
||||
|
|
35
frontend/src/Components/GetAllUsers.tsx
Normal file
35
frontend/src/Components/GetAllUsers.tsx
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { Dispatch, useEffect } from "react";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Gets all usernames in the system and puts them in an array
|
||||
* @param props - A setStateAction for the array you want to put users in
|
||||
* @returns {void} Nothing
|
||||
* @example
|
||||
* const [users, setUsers] = useState<string[]>([]);
|
||||
* GetAllUsers({ setUsersProp: setUsers });
|
||||
*/
|
||||
function GetAllUsers(props: {
|
||||
setUsersProp: Dispatch<React.SetStateAction<string[]>>;
|
||||
}): void {
|
||||
const setUsers: Dispatch<React.SetStateAction<string[]>> = props.setUsersProp;
|
||||
useEffect(() => {
|
||||
const fetchUsers = async (): Promise<void> => {
|
||||
try {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getAllUsers(token);
|
||||
if (response.success) {
|
||||
setUsers(response.data ?? []);
|
||||
} else {
|
||||
console.error("Failed to fetch users:", response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchUsers();
|
||||
}, [setUsers]);
|
||||
}
|
||||
|
||||
export default GetAllUsers;
|
37
frontend/src/Components/GetProjects.tsx
Normal file
37
frontend/src/Components/GetProjects.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Dispatch, useEffect } from "react";
|
||||
import { Project } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Gets all projects that user is a member of
|
||||
* @param props - A setStateAction for the array you want to put projects in
|
||||
* @returns {void} Nothing
|
||||
* @example
|
||||
* const [projects, setProjects] = useState<Project[]>([]);
|
||||
* GetAllUsers({ setProjectsProp: setProjects });
|
||||
*/
|
||||
function GetProjects(props: {
|
||||
setProjectsProp: Dispatch<React.SetStateAction<Project[]>>;
|
||||
}): void {
|
||||
const setProjects: Dispatch<React.SetStateAction<Project[]>> =
|
||||
props.setProjectsProp;
|
||||
useEffect(() => {
|
||||
const fetchUsers = async (): Promise<void> => {
|
||||
try {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getUserProjects(token);
|
||||
if (response.success) {
|
||||
setProjects(response.data ?? []);
|
||||
} else {
|
||||
console.error("Failed to fetch projects:", response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching projects:", error);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchUsers();
|
||||
}, [setProjects]);
|
||||
}
|
||||
|
||||
export default GetProjects;
|
37
frontend/src/Components/GetUsersInProject.tsx
Normal file
37
frontend/src/Components/GetUsersInProject.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Dispatch, useEffect } from "react";
|
||||
import { UserProjectMember } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
|
||||
/**
|
||||
* Gets all projects that user is a member of
|
||||
* @param props - A setStateAction for the array you want to put projects in
|
||||
* @returns {void} Nothing
|
||||
* @example
|
||||
* const [projects, setProjects] = useState<Project[]>([]);
|
||||
* GetAllUsers({ setProjectsProp: setProjects });
|
||||
*/
|
||||
function GetUsersInProject(props: {
|
||||
projectName: string;
|
||||
setUsersProp: Dispatch<React.SetStateAction<UserProjectMember[]>>;
|
||||
}): void {
|
||||
const setUsers: Dispatch<React.SetStateAction<UserProjectMember[]>> =
|
||||
props.setUsersProp;
|
||||
useEffect(() => {
|
||||
const fetchUsers = async (): Promise<void> => {
|
||||
try {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getAllUsersProject(props.projectName, token);
|
||||
if (response.success) {
|
||||
setUsers(response.data ?? []);
|
||||
} else {
|
||||
console.error("Failed to fetch projects:", response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching projects:", error);
|
||||
}
|
||||
};
|
||||
void fetchUsers();
|
||||
}, [props.projectName, setUsers]);
|
||||
}
|
||||
|
||||
export default GetUsersInProject;
|
|
@ -1,7 +1,12 @@
|
|||
//info: Header component to display the header of the page including the logo and user information where thr user can logout
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import backgroundImage from "../assets/1.jpg";
|
||||
|
||||
/**
|
||||
* Renders the header component.
|
||||
* @returns JSX.Element representing the header component.
|
||||
*/
|
||||
function Header(): JSX.Element {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
|
|
|
@ -32,16 +32,11 @@ function LoginCheck(props: {
|
|||
prevAuth = 1;
|
||||
return prevAuth;
|
||||
});
|
||||
} else if (token !== "" && props.username === "pm") {
|
||||
} else if (token !== "") {
|
||||
props.setAuthority((prevAuth) => {
|
||||
prevAuth = 2;
|
||||
return prevAuth;
|
||||
});
|
||||
} else if (token !== "" && props.username === "user") {
|
||||
props.setAuthority((prevAuth) => {
|
||||
prevAuth = 3;
|
||||
return prevAuth;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error("Token was undefined");
|
||||
|
|
|
@ -1,71 +1,114 @@
|
|||
//info: New weekly report form component to create a new weekly report to
|
||||
//sumbit development time, meeting time, admin time, own work time, study time and testing time
|
||||
import { useState } from "react";
|
||||
import type { NewWeeklyReport } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import Button from "./Button";
|
||||
|
||||
/**
|
||||
* Renders a form for creating a new weekly report.
|
||||
* @returns The JSX element representing the new weekly report form.
|
||||
*/
|
||||
export default function NewWeeklyReport(): JSX.Element {
|
||||
const [week, setWeek] = useState<number>(0);
|
||||
const [developmentTime, setDevelopmentTime] = useState<number>();
|
||||
const [meetingTime, setMeetingTime] = useState<number>();
|
||||
const [adminTime, setAdminTime] = useState<number>();
|
||||
const [ownWorkTime, setOwnWorkTime] = useState<number>();
|
||||
const [studyTime, setStudyTime] = useState<number>();
|
||||
const [testingTime, setTestingTime] = useState<number>();
|
||||
const [developmentTime, setDevelopmentTime] = useState<number>(0);
|
||||
const [meetingTime, setMeetingTime] = useState<number>(0);
|
||||
const [adminTime, setAdminTime] = useState<number>(0);
|
||||
const [ownWorkTime, setOwnWorkTime] = useState<number>(0);
|
||||
const [studyTime, setStudyTime] = useState<number>(0);
|
||||
const [testingTime, setTestingTime] = useState<number>(0);
|
||||
|
||||
const { projectName } = useParams();
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
|
||||
const handleNewWeeklyReport = async (): Promise<void> => {
|
||||
const handleNewWeeklyReport = async (): Promise<boolean> => {
|
||||
const newWeeklyReport: NewWeeklyReport = {
|
||||
projectName: projectName ?? "",
|
||||
week: week,
|
||||
developmentTime: developmentTime ?? 0,
|
||||
meetingTime: meetingTime ?? 0,
|
||||
adminTime: adminTime ?? 0,
|
||||
ownWorkTime: ownWorkTime ?? 0,
|
||||
studyTime: studyTime ?? 0,
|
||||
testingTime: testingTime ?? 0,
|
||||
developmentTime: developmentTime,
|
||||
meetingTime: meetingTime,
|
||||
adminTime: adminTime,
|
||||
ownWorkTime: ownWorkTime,
|
||||
studyTime: studyTime,
|
||||
testingTime: testingTime,
|
||||
};
|
||||
|
||||
await api.submitWeeklyReport(newWeeklyReport, token);
|
||||
const response = await api.submitWeeklyReport(newWeeklyReport, token);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const navigate = useNavigate();
|
||||
// Check if the browser is Chrome or Edge
|
||||
const isChromeOrEdge = /Chrome|Edg/.test(navigator.userAgent);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
if (week === 0) {
|
||||
alert("Please enter a week number");
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
void handleNewWeeklyReport();
|
||||
navigate(-1);
|
||||
void (async (): Promise<void> => {
|
||||
if (week === 0 || week > 53 || week < 1) {
|
||||
alert("Please enter a valid week number");
|
||||
return;
|
||||
}
|
||||
|
||||
const success = await handleNewWeeklyReport();
|
||||
if (!success) {
|
||||
alert(
|
||||
"A Time Report for this week already exists, please go to the edit page to edit it or change week number.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
alert("Weekly report submitted successfully");
|
||||
navigate(-1);
|
||||
})();
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col items-center">
|
||||
<input
|
||||
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
||||
type="week"
|
||||
placeholder="Week"
|
||||
onChange={(e) => {
|
||||
const weekNumber = parseInt(e.target.value.split("-W")[1]);
|
||||
setWeek(weekNumber);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||
{isChromeOrEdge ? (
|
||||
<input
|
||||
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
||||
type="week"
|
||||
placeholder="Week"
|
||||
onChange={(e) => {
|
||||
const weekNumber = parseInt(e.target.value.split("-W")[1]);
|
||||
setWeek(weekNumber);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||
event.preventDefault();
|
||||
}}
|
||||
onPaste={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
onPaste={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="w-fill h-[5vh] font-sans text-[3vh] pl-[1vw] rounded-full text-center pt-[1vh] pb-[1vh] border-2 border-black"
|
||||
type="text"
|
||||
placeholder="Week (Numbers Only)"
|
||||
onChange={(e) => {
|
||||
const weekNumber = parseInt(e.target.value);
|
||||
setWeek(weekNumber);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
if (!/\d/.test(keyValue) && keyValue !== "Backspace")
|
||||
event.preventDefault();
|
||||
}}
|
||||
onPaste={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -85,9 +128,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={developmentTime}
|
||||
value={developmentTime === 0 ? "" : developmentTime}
|
||||
onChange={(e) => {
|
||||
setDevelopmentTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setDevelopmentTime(0);
|
||||
return;
|
||||
} else {
|
||||
setDevelopmentTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -104,9 +152,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={meetingTime}
|
||||
value={meetingTime === 0 ? "" : meetingTime}
|
||||
onChange={(e) => {
|
||||
setMeetingTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setMeetingTime(0);
|
||||
return;
|
||||
} else {
|
||||
setMeetingTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -123,9 +176,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={adminTime}
|
||||
value={adminTime === 0 ? "" : adminTime}
|
||||
onChange={(e) => {
|
||||
setAdminTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setAdminTime(0);
|
||||
return;
|
||||
} else {
|
||||
setAdminTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -142,9 +200,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={ownWorkTime}
|
||||
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||
onChange={(e) => {
|
||||
setOwnWorkTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setOwnWorkTime(0);
|
||||
return;
|
||||
} else {
|
||||
setOwnWorkTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -161,9 +224,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={studyTime}
|
||||
value={studyTime === 0 ? "" : studyTime}
|
||||
onChange={(e) => {
|
||||
setStudyTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setStudyTime(0);
|
||||
return;
|
||||
} else {
|
||||
setStudyTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
@ -180,9 +248,14 @@ export default function NewWeeklyReport(): JSX.Element {
|
|||
type="number"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={testingTime}
|
||||
value={testingTime === 0 ? "" : testingTime}
|
||||
onChange={(e) => {
|
||||
setTestingTime(parseInt(e.target.value));
|
||||
if (e.target.value === "") {
|
||||
setTestingTime(0);
|
||||
return;
|
||||
} else {
|
||||
setTestingTime(parseInt(e.target.value));
|
||||
}
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
const keyValue = event.key;
|
||||
|
|
153
frontend/src/Components/OtherUsersTR.tsx
Normal file
153
frontend/src/Components/OtherUsersTR.tsx
Normal file
|
@ -0,0 +1,153 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { WeeklyReport } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders the component for editing a weekly report.
|
||||
* @returns JSX.Element
|
||||
*/
|
||||
|
||||
//This component does not yet work as intended. It is supposed to display the weekly report of a user in a project.
|
||||
export default function OtherUsersTR(): JSX.Element {
|
||||
const [week, setWeek] = useState(0);
|
||||
const [developmentTime, setDevelopmentTime] = useState(0);
|
||||
const [meetingTime, setMeetingTime] = useState(0);
|
||||
const [adminTime, setAdminTime] = useState(0);
|
||||
const [ownWorkTime, setOwnWorkTime] = useState(0);
|
||||
const [studyTime, setStudyTime] = useState(0);
|
||||
const [testingTime, setTestingTime] = useState(0);
|
||||
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const { projectName } = useParams();
|
||||
const { username } = useParams();
|
||||
const { fetchedWeek } = useParams();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUsersWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
projectName ?? "",
|
||||
fetchedWeek?.toString() ?? "0",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: WeeklyReport = response.data ?? {
|
||||
reportId: 0,
|
||||
userId: 0,
|
||||
projectId: 0,
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchUsersWeeklyReport();
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-[30px] font-bold">{username}'s Report</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="flex flex-col w-1/2 border-b-2 border-black items-center justify-center">
|
||||
<h1 className="font-bold text-[30px]"> Week: {week}</h1>
|
||||
</div>
|
||||
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">Activity</th>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||
Total Time (min)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-black">
|
||||
<tr className="h-[10vh]">
|
||||
<td>Development</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={developmentTime === 0 ? "" : developmentTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Meeting</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={meetingTime === 0 ? "" : meetingTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Administration</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={adminTime === 0 ? "" : adminTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Own Work</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Studies</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={studyTime === 0 ? "" : studyTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Testing</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={testingTime === 0 ? "" : testingTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
34
frontend/src/Components/PMProjectMenu.tsx
Normal file
34
frontend/src/Components/PMProjectMenu.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { Link, useParams } from "react-router-dom";
|
||||
import { JSX } from "react/jsx-runtime";
|
||||
|
||||
function PMProjectMenu(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">{projectName}</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[5vh] p-[30px]">
|
||||
<Link to={`/timeReports/${projectName}/`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Your Time Reports
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to={`/newTimeReport/${projectName}`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
New Time Report
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to={`/projectMembers/${projectName}`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Statistics
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to={`/unsignedReports/${projectName}`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Unsigned Time Reports
|
||||
</h1>
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default PMProjectMenu;
|
79
frontend/src/Components/ProjectInfoModal.tsx
Normal file
79
frontend/src/Components/ProjectInfoModal.tsx
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { useState } from "react";
|
||||
import Button from "./Button";
|
||||
import { UserProjectMember } from "../Types/goTypes";
|
||||
import GetUsersInProject from "./GetUsersInProject";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
function ProjectInfoModal(props: {
|
||||
isVisible: boolean;
|
||||
projectname: string;
|
||||
onClose: () => void;
|
||||
onClick: (username: string) => void;
|
||||
}): JSX.Element {
|
||||
const [users, setUsers] = useState<UserProjectMember[]>([]);
|
||||
GetUsersInProject({ projectName: props.projectname, setUsersProp: setUsers });
|
||||
if (!props.isVisible) return <></>;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||
flex justify-center items-center"
|
||||
>
|
||||
<div className="border-4 border-black bg-white p-2 rounded-2xl text-center h-[47vh] w-[40] flex flex-col">
|
||||
<div className="pl-20 pr-20">
|
||||
<h1 className="font-bold text-[32px] mb-[20px]">
|
||||
{localStorage.getItem("projectName") ?? ""}
|
||||
</h1>
|
||||
<h2 className="font-bold text-[24px] mb-[20px]">Project members:</h2>
|
||||
<div className="border-2 border-black p-2 rounded-lg text-center overflow-scroll h-[26vh]">
|
||||
<ul className="text-left font-medium space-y-2">
|
||||
<div></div>
|
||||
{users.map((user) => (
|
||||
<li
|
||||
className="items-start p-1 border-2 border-black rounded-lg bg-orange-200 hover:bg-orange-600 hover:text-slate-100 hover:cursor-pointer"
|
||||
key={user.Username}
|
||||
onClick={() => {
|
||||
props.onClick(user.Username);
|
||||
}}
|
||||
>
|
||||
<span>
|
||||
Name: {user.Username}
|
||||
<div></div>
|
||||
Role: {user.UserRole}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-x-16">
|
||||
<Button
|
||||
text={"Delete"}
|
||||
onClick={function (): void {
|
||||
//DELETE PROJECT
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Link to={"/adminProjectAddMember"}>
|
||||
<Button
|
||||
text={"Add Member"}
|
||||
onClick={function (): void {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
</Link>
|
||||
<Button
|
||||
text={"Close"}
|
||||
onClick={function (): void {
|
||||
props.onClose();
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectInfoModal;
|
81
frontend/src/Components/ProjectListAdmin.tsx
Normal file
81
frontend/src/Components/ProjectListAdmin.tsx
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { useState } from "react";
|
||||
import { NewProject } from "../Types/goTypes";
|
||||
import ProjectInfoModal from "./ProjectInfoModal";
|
||||
import UserInfoModal from "./UserInfoModal";
|
||||
|
||||
/**
|
||||
* A list of projects for admin manage projects page, that sets an onClick
|
||||
* function for eact project <li> element, which displays a modul with
|
||||
* user info.
|
||||
* @param props - An array of projects to display
|
||||
* @returns {JSX.Element} The project list
|
||||
* @example
|
||||
* const projects: NewProject[] = [{ name: "Project", description: "New" }];
|
||||
* return <ProjectListAdmin projects={projects} />
|
||||
*/
|
||||
|
||||
export function ProjectListAdmin(props: {
|
||||
projects: NewProject[];
|
||||
}): JSX.Element {
|
||||
const [projectModalVisible, setProjectModalVisible] = useState(false);
|
||||
const [projectname, setProjectname] = useState("");
|
||||
const [userModalVisible, setUserModalVisible] = useState(false);
|
||||
const [username, setUsername] = useState("");
|
||||
|
||||
const handleClickUser = (username: string): void => {
|
||||
setUsername(username);
|
||||
setUserModalVisible(true);
|
||||
};
|
||||
|
||||
const handleClickProject = (projectname: string): void => {
|
||||
setProjectname(projectname);
|
||||
localStorage.setItem("projectName", projectname);
|
||||
setProjectModalVisible(true);
|
||||
};
|
||||
|
||||
const handleCloseProject = (): void => {
|
||||
setProjectname("");
|
||||
setProjectModalVisible(false);
|
||||
};
|
||||
|
||||
const handleCloseUser = (): void => {
|
||||
setProjectname("");
|
||||
setUserModalVisible(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProjectInfoModal
|
||||
onClose={handleCloseProject}
|
||||
onClick={handleClickUser}
|
||||
isVisible={projectModalVisible}
|
||||
projectname={projectname}
|
||||
/>
|
||||
<UserInfoModal
|
||||
manageMember={true}
|
||||
onClose={handleCloseUser}
|
||||
//TODO: CHANGE TO REMOVE USER FROM PROJECT
|
||||
onDelete={() => {
|
||||
return;
|
||||
}}
|
||||
isVisible={userModalVisible}
|
||||
username={username}
|
||||
/>
|
||||
<div>
|
||||
<ul className="font-bold underline text-[30px] cursor-pointer padding">
|
||||
{props.projects.map((project) => (
|
||||
<li
|
||||
className="pt-5"
|
||||
key={project.name}
|
||||
onClick={() => {
|
||||
handleClickProject(project.name);
|
||||
}}
|
||||
>
|
||||
{project.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
63
frontend/src/Components/ProjectMembers.tsx
Normal file
63
frontend/src/Components/ProjectMembers.tsx
Normal file
|
@ -0,0 +1,63 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { api } from "../API/API";
|
||||
import { UserProjectMember } from "../Types/goTypes";
|
||||
|
||||
function ProjectMembers(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
const [projectMembers, setProjectMembers] = useState<UserProjectMember[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const getProjectMembers = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getAllUsersProject(projectName ?? "", token);
|
||||
console.log(response);
|
||||
if (response.success) {
|
||||
setProjectMembers(response.data ?? []);
|
||||
} else {
|
||||
console.error(response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void getProjectMembers();
|
||||
}, [projectName]);
|
||||
|
||||
interface ProjectMember {
|
||||
Username: string;
|
||||
UserRole: string;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
All Members In: {projectName}{" "}
|
||||
</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[70vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px] text-[20px]">
|
||||
{projectMembers.map((projectMember: ProjectMember, index: number) => (
|
||||
<h1 key={index} className="border-b-2 border-black w-full">
|
||||
<div className="flex justify-between">
|
||||
<div className="flex">
|
||||
<h1>{projectMember.Username}</h1>
|
||||
<span className="ml-6 mr-2 font-bold">Role:</span>
|
||||
<h1>{projectMember.UserRole}</h1>
|
||||
</div>
|
||||
<div className="flex">
|
||||
<div className="ml-auto flex space-x-4">
|
||||
<Link
|
||||
to={`/otherUsersTimeReports/${projectName}/${projectMember.Username}`}
|
||||
>
|
||||
<h1 className="underline cursor-pointer font-bold">
|
||||
View Reports
|
||||
</h1>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</h1>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectMembers;
|
|
@ -4,15 +4,16 @@ import { api } from "../API/API";
|
|||
import Logo from "../assets/Logo.svg";
|
||||
import Button from "./Button";
|
||||
import InputField from "./InputField";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders a registration form for the admin to add new users in.
|
||||
* @returns The JSX element representing the registration form.
|
||||
*/
|
||||
export default function Register(): JSX.Element {
|
||||
const [username, setUsername] = useState<string>();
|
||||
const [password, setPassword] = useState<string>();
|
||||
const [errMessage, setErrMessage] = useState<string>();
|
||||
|
||||
const nav = useNavigate();
|
||||
|
||||
const handleRegister = async (): Promise<void> => {
|
||||
const newUser: NewUser = {
|
||||
username: username ?? "",
|
||||
|
@ -20,8 +21,9 @@ export default function Register(): JSX.Element {
|
|||
};
|
||||
const response = await api.registerUser(newUser);
|
||||
if (response.success) {
|
||||
nav("/"); // Instantly navigate to the login page
|
||||
alert("User added!");
|
||||
} else {
|
||||
alert("User not added");
|
||||
setErrMessage(response.message ?? "Unknown error");
|
||||
console.error(errMessage);
|
||||
}
|
||||
|
|
175
frontend/src/Components/TimePerActivity.tsx
Normal file
175
frontend/src/Components/TimePerActivity.tsx
Normal file
|
@ -0,0 +1,175 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders the component for showing total time per role in a project.
|
||||
* @returns JSX.Element
|
||||
*/
|
||||
export default function TimePerRole(): JSX.Element {
|
||||
const [developmentTime, setDevelopmentTime] = useState<number>();
|
||||
const [meetingTime, setMeetingTime] = useState<number>();
|
||||
const [adminTime, setAdminTime] = useState<number>();
|
||||
const [ownWorkTime, setOwnWorkTime] = useState<number>();
|
||||
const [studyTime, setStudyTime] = useState<number>();
|
||||
const [testingTime, setTestingTime] = useState<number>();
|
||||
|
||||
// const token = localStorage.getItem("accessToken") ?? "";
|
||||
// const username = localStorage.getItem("username") ?? "";
|
||||
const { projectName } = useParams();
|
||||
|
||||
// const fetchTimePerRole = async (): Promise<void> => {
|
||||
// const response = await api.getTimePerRole(
|
||||
// username,
|
||||
// projectName ?? "",
|
||||
// token,
|
||||
// );
|
||||
// {
|
||||
// if (response.success) {
|
||||
// const report: TimePerRole = response.data ?? {
|
||||
// PManagerTime: 0,
|
||||
// SManagerTime: 0,
|
||||
// DeveloperTime: 0,
|
||||
// TesterTime: 0,
|
||||
// };
|
||||
// } else {
|
||||
// console.error("Failed to fetch weekly report:", response.message);
|
||||
// }
|
||||
// }
|
||||
|
||||
interface TimePerActivity {
|
||||
developmentTime: number;
|
||||
meetingTime: number;
|
||||
adminTime: number;
|
||||
ownWorkTime: number;
|
||||
studyTime: number;
|
||||
testingTime: number;
|
||||
}
|
||||
|
||||
const fetchTimePerActivity = async (): Promise<void> => {
|
||||
// Use mock data
|
||||
const report: TimePerActivity = {
|
||||
developmentTime: 100,
|
||||
meetingTime: 200,
|
||||
adminTime: 300,
|
||||
ownWorkTime: 50,
|
||||
studyTime: 75,
|
||||
testingTime: 110,
|
||||
};
|
||||
|
||||
// Set the state with the mock data
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
|
||||
await Promise.resolve();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void fetchTimePerActivity();
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
Total Time Per Activity In: {projectName}{" "}
|
||||
</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<div className="flex flex-col items-center">
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">Activity</th>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||
Total Time (min)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-black">
|
||||
<tr className="h-[10vh]">
|
||||
<td>Development</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={developmentTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Meeting</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={meetingTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Administration</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={adminTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Own Work</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={ownWorkTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Studies</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={studyTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Testing</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={testingTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
141
frontend/src/Components/TimePerRole.tsx
Normal file
141
frontend/src/Components/TimePerRole.tsx
Normal file
|
@ -0,0 +1,141 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
/**
|
||||
* Renders the component for showing total time per role in a project.
|
||||
* @returns JSX.Element
|
||||
*/
|
||||
export default function TimePerRole(): JSX.Element {
|
||||
const [PManagerTime, setPManagerTime] = useState(0);
|
||||
const [SManagerTime, setSManagerTime] = useState(0);
|
||||
const [DeveloperTime, setDeveloperTime] = useState(0);
|
||||
const [TesterTime, setTesterTime] = useState(0);
|
||||
|
||||
// const token = localStorage.getItem("accessToken") ?? "";
|
||||
// const username = localStorage.getItem("username") ?? "";
|
||||
const { projectName } = useParams();
|
||||
|
||||
// const fetchTimePerRole = async (): Promise<void> => {
|
||||
// const response = await api.getTimePerRole(
|
||||
// username,
|
||||
// projectName ?? "",
|
||||
// token,
|
||||
// );
|
||||
// {
|
||||
// if (response.success) {
|
||||
// const report: TimePerRole = response.data ?? {
|
||||
// PManagerTime: 0,
|
||||
// SManagerTime: 0,
|
||||
// DeveloperTime: 0,
|
||||
// TesterTime: 0,
|
||||
// };
|
||||
// } else {
|
||||
// console.error("Failed to fetch weekly report:", response.message);
|
||||
// }
|
||||
// }
|
||||
|
||||
interface TimePerRole {
|
||||
PManager: number;
|
||||
SManager: number;
|
||||
Developer: number;
|
||||
Tester: number;
|
||||
}
|
||||
|
||||
const fetchTimePerRole = async (): Promise<void> => {
|
||||
// Use mock data
|
||||
const report: TimePerRole = {
|
||||
PManager: 120,
|
||||
SManager: 80,
|
||||
Developer: 200,
|
||||
Tester: 150,
|
||||
};
|
||||
|
||||
// Set the state with the mock data
|
||||
setPManagerTime(report.PManager);
|
||||
setSManagerTime(report.SManager);
|
||||
setDeveloperTime(report.Developer);
|
||||
setTesterTime(report.Tester);
|
||||
|
||||
await Promise.resolve();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void fetchTimePerRole();
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
Total Time Per Role In: {projectName}{" "}
|
||||
</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<div className="flex flex-col items-center">
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">Role</th>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||
Total Time (min)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-black">
|
||||
<tr className="h-[10vh]">
|
||||
<td>Project Manager</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={PManagerTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>System Manager</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={SManagerTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Administration</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={DeveloperTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Own Work</td>
|
||||
<td>
|
||||
<input
|
||||
type="string"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={TesterTime}
|
||||
onKeyDown={(event) => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -5,23 +5,38 @@ import UserProjectListAdmin from "./UserProjectListAdmin";
|
|||
|
||||
function UserInfoModal(props: {
|
||||
isVisible: boolean;
|
||||
manageMember: boolean;
|
||||
username: string;
|
||||
onClose: () => void;
|
||||
onDelete: (username: string) => void;
|
||||
}): JSX.Element {
|
||||
if (!props.isVisible) return <></>;
|
||||
|
||||
const ManageUserOrMember = (check: boolean): JSX.Element => {
|
||||
if (check) {
|
||||
return (
|
||||
<Link to="/AdminChangeRole">
|
||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
||||
(Change Role)
|
||||
</p>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Link to="/AdminChangeUserName">
|
||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
||||
(Change Username)
|
||||
</p>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 bg-black bg-opacity-30 backdrop-blur-sm
|
||||
flex justify-center items-center"
|
||||
>
|
||||
<div className="border-4 border-black bg-white p-2 rounded-lg text-center">
|
||||
<div className="border-4 border-black bg-white p-2 rounded-lg text-center flex flex-col">
|
||||
<p className="font-bold text-[30px]">{props.username}</p>
|
||||
<Link to="/AdminChangeUserName">
|
||||
<p className="mb-[20px] hover:font-bold hover:cursor-pointer underline">
|
||||
(Change Username)
|
||||
</p>
|
||||
</Link>
|
||||
{ManageUserOrMember(props.manageMember)}
|
||||
<div>
|
||||
<h2 className="font-bold text-[22px] mb-[20px]">
|
||||
Member of these projects:
|
||||
|
@ -34,7 +49,13 @@ function UserInfoModal(props: {
|
|||
<Button
|
||||
text={"Delete"}
|
||||
onClick={function (): void {
|
||||
DeleteUser({ usernameToDelete: props.username });
|
||||
if (
|
||||
window.confirm("Are you sure you want to delete this user?")
|
||||
) {
|
||||
DeleteUser({
|
||||
usernameToDelete: props.username,
|
||||
});
|
||||
}
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
import { useState } from "react";
|
||||
import { PublicUser } from "../Types/goTypes";
|
||||
import UserInfoModal from "./UserInfoModal";
|
||||
|
||||
/**
|
||||
* The props for the UserProps component
|
||||
*/
|
||||
interface UserProps {
|
||||
users: PublicUser[];
|
||||
}
|
||||
import DeleteUser from "./DeleteUser";
|
||||
|
||||
/**
|
||||
* A list of users for admin manage users page, that sets an onClick
|
||||
|
@ -20,7 +13,7 @@ interface UserProps {
|
|||
* return <UserList users={users} />;
|
||||
*/
|
||||
|
||||
export function UserListAdmin(props: UserProps): JSX.Element {
|
||||
export function UserListAdmin(props: { users: string[] }): JSX.Element {
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [username, setUsername] = useState("");
|
||||
|
||||
|
@ -37,7 +30,9 @@ export function UserListAdmin(props: UserProps): JSX.Element {
|
|||
return (
|
||||
<>
|
||||
<UserInfoModal
|
||||
manageMember={false}
|
||||
onClose={handleClose}
|
||||
onDelete={() => DeleteUser}
|
||||
isVisible={modalVisible}
|
||||
username={username}
|
||||
/>
|
||||
|
@ -46,12 +41,12 @@ export function UserListAdmin(props: UserProps): JSX.Element {
|
|||
{props.users.map((user) => (
|
||||
<li
|
||||
className="pt-5"
|
||||
key={user.userId}
|
||||
key={user}
|
||||
onClick={() => {
|
||||
handleClick(user.username);
|
||||
handleClick(user);
|
||||
}}
|
||||
>
|
||||
{user.username}
|
||||
{user}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
|
32
frontend/src/Components/UserProjectMenu.tsx
Normal file
32
frontend/src/Components/UserProjectMenu.tsx
Normal file
|
@ -0,0 +1,32 @@
|
|||
//info: User project menu component to display the user project menu where the user can navigate to
|
||||
//existing time reports in a project and create a new time report
|
||||
import { useParams, Link } from "react-router-dom";
|
||||
import { JSX } from "react/jsx-runtime";
|
||||
|
||||
/**
|
||||
* Renders the user project menu component.
|
||||
*
|
||||
* @returns JSX.Element representing the user project menu.
|
||||
*/
|
||||
function UserProjectMenu(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">{projectName}</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||
<Link to={`/timeReports/${projectName}/`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Your Time Reports
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to={`/newTimeReport/${projectName}`}>
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
New Time Report
|
||||
</h1>
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default UserProjectMenu;
|
188
frontend/src/Components/ViewOtherTimeReport.tsx
Normal file
188
frontend/src/Components/ViewOtherTimeReport.tsx
Normal file
|
@ -0,0 +1,188 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { WeeklyReport, NewWeeklyReport } from "../Types/goTypes";
|
||||
import { api } from "../API/API";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import Button from "./Button";
|
||||
|
||||
/**
|
||||
* Renders the component for editing a weekly report.
|
||||
* @returns JSX.Element
|
||||
*/
|
||||
|
||||
//This component does not yet work as intended. It is supposed to display the weekly report of a user in a project.
|
||||
export default function GetOtherUsersReport(): JSX.Element {
|
||||
const [week, setWeek] = useState(0);
|
||||
const [developmentTime, setDevelopmentTime] = useState(0);
|
||||
const [meetingTime, setMeetingTime] = useState(0);
|
||||
const [adminTime, setAdminTime] = useState(0);
|
||||
const [ownWorkTime, setOwnWorkTime] = useState(0);
|
||||
const [studyTime, setStudyTime] = useState(0);
|
||||
const [testingTime, setTestingTime] = useState(0);
|
||||
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const { projectName } = useParams();
|
||||
const { username } = useParams();
|
||||
const { fetchedWeek } = useParams();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUsersWeeklyReport = async (): Promise<void> => {
|
||||
const response = await api.getWeeklyReport(
|
||||
projectName ?? "",
|
||||
fetchedWeek?.toString() ?? "0",
|
||||
token,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
const report: WeeklyReport = response.data ?? {
|
||||
reportId: 0,
|
||||
userId: 0,
|
||||
projectId: 0,
|
||||
week: 0,
|
||||
developmentTime: 0,
|
||||
meetingTime: 0,
|
||||
adminTime: 0,
|
||||
ownWorkTime: 0,
|
||||
studyTime: 0,
|
||||
testingTime: 0,
|
||||
};
|
||||
setWeek(report.week);
|
||||
setDevelopmentTime(report.developmentTime);
|
||||
setMeetingTime(report.meetingTime);
|
||||
setAdminTime(report.adminTime);
|
||||
setOwnWorkTime(report.ownWorkTime);
|
||||
setStudyTime(report.studyTime);
|
||||
setTestingTime(report.testingTime);
|
||||
} else {
|
||||
console.error("Failed to fetch weekly report:", response.message);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchUsersWeeklyReport();
|
||||
});
|
||||
|
||||
const handleSignWeeklyReport = async (): Promise<void> => {
|
||||
const newWeeklyReport: NewWeeklyReport = {
|
||||
projectName: projectName ?? "",
|
||||
week,
|
||||
developmentTime,
|
||||
meetingTime,
|
||||
adminTime,
|
||||
ownWorkTime,
|
||||
studyTime,
|
||||
testingTime,
|
||||
};
|
||||
|
||||
await api.submitWeeklyReport(newWeeklyReport, token);
|
||||
};
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-[30px] font-bold">{username}'s Report</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col justify-start min-h-[65vh] h-fit w-[50vw] rounded-3xl overflow-scroll space-y-[2vh] p-[30px] items-center">
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void handleSignWeeklyReport();
|
||||
navigate(-1);
|
||||
}}
|
||||
>
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="flex flex-col w-1/2 border-b-2 border-black items-center justify-center">
|
||||
<h1 className="font-bold text-[30px]"> Week: {week}</h1>
|
||||
</div>
|
||||
|
||||
<table className="w-full text-center divide-y divide-x divide-white text-[30px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||
Activity
|
||||
</th>
|
||||
<th className="w-1/2 py-2 border-b-2 border-black">
|
||||
Total Time (min)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-black">
|
||||
<tr className="h-[10vh]">
|
||||
<td>Development</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={developmentTime === 0 ? "" : developmentTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Meeting</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={meetingTime === 0 ? "" : meetingTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Administration</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={adminTime === 0 ? "" : adminTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Own Work</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={ownWorkTime === 0 ? "" : ownWorkTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Studies</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={studyTime === 0 ? "" : studyTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="h-[10vh]">
|
||||
<td>Testing</td>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
min="0"
|
||||
className="border-2 border-black rounded-md text-center w-1/2"
|
||||
value={testingTime === 0 ? "" : testingTime}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<Button
|
||||
text="Sign Report"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="submit"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -2,9 +2,22 @@ import { Link } from "react-router-dom";
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
import { ProjectListAdmin } from "../../Components/ProjectListAdmin";
|
||||
import { Project } from "../../Types/goTypes";
|
||||
import GetProjects from "../../Components/GetProjects";
|
||||
import { useState } from "react";
|
||||
|
||||
function AdminManageProjects(): JSX.Element {
|
||||
const content = <></>;
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
GetProjects({ setProjectsProp: setProjects });
|
||||
const content = (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">Manage Projects</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center h-[65vh] w-[50vw] rounded-3xl content-center overflow-scroll space-y-[10vh] p-[30px]">
|
||||
<ProjectListAdmin projects={projects} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
|
|
|
@ -2,15 +2,13 @@ import BasicWindow from "../../Components/BasicWindow";
|
|||
import Button from "../../Components/Button";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import { UserListAdmin } from "../../Components/UserListAdmin";
|
||||
import { PublicUser } from "../../Types/goTypes";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import GetAllUsers from "../../Components/GetAllUsers";
|
||||
import { useState } from "react";
|
||||
|
||||
function AdminManageUsers(): JSX.Element {
|
||||
//TODO: Change so that it reads users from database
|
||||
const users: PublicUser[] = [];
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
users.push({ userId: "id" + i, username: "Example User " + i });
|
||||
}
|
||||
const [users, setUsers] = useState<string[]>([]);
|
||||
GetAllUsers({ setUsersProp: setUsers });
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
import AddUserToProject from "../../Components/AddUserToProject";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
function AdminProjectAddMember(): JSX.Element {
|
||||
const content = <></>;
|
||||
const content = <AddUserToProject />;
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
<Button
|
||||
text="Add"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
const buttons = <></>;
|
||||
|
||||
return <BasicWindow content={content} buttons={buttons} />;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
|
@ -13,13 +14,7 @@ function AdminProjectChangeUserRole(): JSX.Element {
|
|||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
|
@ -13,13 +14,7 @@ function AdminProjectManageMembers(): JSX.Element {
|
|||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -1,28 +1,33 @@
|
|||
import { useParams } from "react-router-dom";
|
||||
import { api } from "../../API/API";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
async function handleDeleteProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<void> {
|
||||
await api.removeProject(projectName, token);
|
||||
}
|
||||
|
||||
function AdminProjectPage(): JSX.Element {
|
||||
const content = <></>;
|
||||
const { projectName } = useParams();
|
||||
const token = localStorage.getItem("accessToken");
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
<Button
|
||||
text="Delete"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
onClick={() => handleDeleteProject(projectName, token)}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
return <BasicWindow content={content} buttons={buttons} />;
|
||||
}
|
||||
|
||||
export default AdminProjectPage;
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
function AdminProjectStatistics(): JSX.Element {
|
||||
const content = <></>;
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
|
||||
|
@ -13,13 +14,7 @@ function AdminProjectViewMemberInfo(): JSX.Element {
|
|||
}}
|
||||
type="button"
|
||||
/>
|
||||
<Button
|
||||
text="Back"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@ function App(): JSX.Element {
|
|||
if (authority === 1) {
|
||||
navigate("/admin");
|
||||
} else if (authority === 2) {
|
||||
navigate("/pm");
|
||||
} else if (authority === 3) {
|
||||
navigate("/yourProjects");
|
||||
}
|
||||
}, [authority, navigate]);
|
||||
|
|
|
@ -4,23 +4,23 @@ body{
|
|||
|
||||
@keyframes backgroundTransition {
|
||||
0% {
|
||||
background-image: url('src/assets/1.jpg');
|
||||
background-image: url('../assets/1.jpg');
|
||||
animation-timing-function: ease-out;
|
||||
}
|
||||
25% {
|
||||
background-image: url('src/assets/2.jpg');
|
||||
background-image: url('../assets/2.jpg');
|
||||
animation-timing-function: ease-in;
|
||||
}
|
||||
50% {
|
||||
background-image: url('src/assets/3.jpg');
|
||||
background-image: url('../assets/3.jpg');
|
||||
animation-timing-function: ease-out;
|
||||
}
|
||||
75% {
|
||||
background-image: url('src/assets/4.jpg');
|
||||
background-image: url('../assets/4.jpg');
|
||||
animation-timing-function: ease-in;
|
||||
}
|
||||
100% {
|
||||
background-image: url('src/assets/1.jpg');
|
||||
background-image: url('../assets/1.jpg');
|
||||
animation-timing-function: ease-out;
|
||||
}
|
||||
}
|
|
@ -1,19 +1,16 @@
|
|||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import ChangeRoles from "../../Components/ChangeRoles";
|
||||
|
||||
function ChangeRole(): JSX.Element {
|
||||
const content = <></>;
|
||||
const content = (
|
||||
<>
|
||||
<ChangeRoles />
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
<Button
|
||||
text="Save"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type="button"
|
||||
/>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import AllTimeReportsInProjectOtherUser from "../../Components/AllTimeReportsInProjectOtherUser";
|
||||
|
||||
function PMOtherUsersTR(): JSX.Element {
|
||||
const content = <></>;
|
||||
const content = (
|
||||
<>
|
||||
<AllTimeReportsInProjectOtherUser />
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import Button from "../../Components/Button";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import ProjectMembers from "../../Components/ProjectMembers";
|
||||
|
||||
function PMProjectMembers(): JSX.Element {
|
||||
const content = <></>;
|
||||
const { projectName } = useParams();
|
||||
const content = (
|
||||
<>
|
||||
<ProjectMembers />
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
<Link to="/PM-time-activity">
|
||||
<Link to={`/PMtimeactivity/${projectName}`}>
|
||||
<Button
|
||||
text="Time / Activity"
|
||||
onClick={(): void => {
|
||||
|
@ -17,15 +23,6 @@ function PMProjectMembers(): JSX.Element {
|
|||
type={"button"}
|
||||
/>
|
||||
</Link>
|
||||
<Link to="/PM-time-role">
|
||||
<Button
|
||||
text="Time / Role"
|
||||
onClick={(): void => {
|
||||
return;
|
||||
}}
|
||||
type={"button"}
|
||||
/>
|
||||
</Link>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -1,36 +1,21 @@
|
|||
import { Link } from "react-router-dom";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import { JSX } from "react/jsx-runtime";
|
||||
import PMProjectMenu from "../../Components/PMProjectMenu";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
|
||||
function PMProjectPage(): JSX.Element {
|
||||
const content = (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">ProjectNameExample</h1>
|
||||
<div className="border-4 border-black bg-white flex flex-col items-center justify-center min-h-[65vh] h-fit w-[50vw] rounded-3xl content-center overflow-scroll space-y-[5vh] p-[30px]">
|
||||
<Link to="/project-page">
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Your Time Reports
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to="/new-time-report">
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
New Time Report
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to="/project-members">
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Statistics
|
||||
</h1>
|
||||
</Link>
|
||||
<Link to="/PM-unsigned-reports">
|
||||
<h1 className="font-bold underline text-[30px] cursor-pointer">
|
||||
Unsigned Time Reports
|
||||
</h1>
|
||||
</Link>
|
||||
</div>
|
||||
<PMProjectMenu />
|
||||
</>
|
||||
);
|
||||
|
||||
return <BasicWindow content={content} buttons={undefined} />;
|
||||
const buttons = (
|
||||
<>
|
||||
<BackButton />
|
||||
</>
|
||||
);
|
||||
|
||||
return <BasicWindow content={content} buttons={buttons} />;
|
||||
}
|
||||
export default PMProjectPage;
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import BackButton from "../../Components/BackButton";
|
||||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import TimeReport from "../../Components/NewWeeklyReport";
|
||||
import TimePerActivity from "../../Components/TimePerActivity";
|
||||
|
||||
function PMTotalTimeActivity(): JSX.Element {
|
||||
const content = (
|
||||
<>
|
||||
<h1 className="font-bold text-[30px] mb-[20px]">
|
||||
Total Time Per Activity
|
||||
</h1>
|
||||
<TimeReport />
|
||||
<TimePerActivity />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import TimePerRole from "../../Components/TimePerRole";
|
||||
|
||||
function PMTotalTimeRole(): JSX.Element {
|
||||
const content = <></>;
|
||||
const content = (
|
||||
<>
|
||||
<TimePerRole />
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import BasicWindow from "../../Components/BasicWindow";
|
||||
import BackButton from "../../Components/BackButton";
|
||||
import DisplayUnsignedReports from "../../Components/DisplayUnsignedReports";
|
||||
|
||||
function PMUnsignedReports(): JSX.Element {
|
||||
const content = <></>;
|
||||
const content = (
|
||||
<>
|
||||
<DisplayUnsignedReports />
|
||||
</>
|
||||
);
|
||||
|
||||
const buttons = (
|
||||
<>
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue