mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-07 04:09:17 +02:00
added UserDefined Module Naming
This commit is contained in:
3
backend/model/eventModel.go
Normal file
3
backend/model/eventModel.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type Events []*Event
|
@@ -22,4 +22,8 @@ type Entry struct {
|
|||||||
// Entries is a collection of entries
|
// Entries is a collection of entries
|
||||||
type Entries []*Entry
|
type Entries []*Entry
|
||||||
|
|
||||||
type Events []*Event
|
type FeedCollection struct {
|
||||||
|
Name string `db:"Name" json:"Name"`
|
||||||
|
Course string `db:"course" json:"Course"`
|
||||||
|
UserDefinedName string `db:"userDefinedName" json:"UserDefinedName"`
|
||||||
|
}
|
||||||
|
@@ -1,15 +1,11 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jordic/goics"
|
|
||||||
"github.com/pocketbase/dbx"
|
"github.com/pocketbase/dbx"
|
||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
"github.com/pocketbase/pocketbase/models"
|
"github.com/pocketbase/pocketbase/models"
|
||||||
"htwkalender/model"
|
"htwkalender/model"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"unicode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SaveEvents(seminarGroup []model.SeminarGroup, collection *models.Collection, app *pocketbase.PocketBase) ([]*models.Record, error) {
|
func SaveEvents(seminarGroup []model.SeminarGroup, collection *models.Collection, app *pocketbase.PocketBase) ([]*models.Record, error) {
|
||||||
@@ -81,60 +77,10 @@ func findEventByDayWeekStartEndNameCourse(event model.Event, course string, app
|
|||||||
return &event, err
|
return &event, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(s []string, e string) bool {
|
|
||||||
for _, a := range s {
|
|
||||||
if a == e {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRooms function to get all rooms from database that are stored as a string in the Event struct
|
|
||||||
func GetRooms(app *pocketbase.PocketBase) []string {
|
|
||||||
|
|
||||||
var events []struct {
|
|
||||||
Rooms string `db:"Rooms" json:"Rooms"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// get all rooms from event records in the events collection
|
|
||||||
err := app.Dao().DB().Select("Rooms").From("events").All(&events)
|
|
||||||
if err != nil {
|
|
||||||
print("Error while getting rooms from database: ", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var roomArray []string
|
|
||||||
|
|
||||||
for _, event := range events {
|
|
||||||
var room = strings.Split(event.Rooms, " ")
|
|
||||||
//split string room by space and add each room to array if it is not already in there
|
|
||||||
for _, r := range room {
|
|
||||||
var text = strings.TrimSpace(r)
|
|
||||||
if !contains(roomArray, text) && !strings.Contains(text, " ") && len(text) >= 1 {
|
|
||||||
roomArray = append(roomArray, text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return roomArray
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string) []model.Event {
|
|
||||||
var events []model.Event
|
|
||||||
|
|
||||||
// get all events from event records in the events collection
|
|
||||||
err := app.Dao().DB().Select("*").From("events").Where(dbx.Like("Rooms", room)).AndWhere(dbx.Like("Start", date)).All(&events)
|
|
||||||
if err != nil {
|
|
||||||
print("Error while getting events from database: ", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return events
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets all events for specific course and semester
|
// gets all events for specific course and semester
|
||||||
// TODO add filter for year
|
// TODO add filter for year
|
||||||
func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, semester string) Events {
|
func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, semester string) model.Events {
|
||||||
var events Events
|
var events model.Events
|
||||||
// get all events from event records in the events collection
|
// get all events from event records in the events collection
|
||||||
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp("course = {:course} AND semester = {:semester}", dbx.Params{"course": course, "semester": semester})).All(&events)
|
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp("course = {:course} AND semester = {:semester}", dbx.Params{"course": course, "semester": semester})).All(&events)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -144,12 +90,9 @@ func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, seme
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPlanForModules(app *pocketbase.PocketBase, modules []struct {
|
func GetPlanForModules(app *pocketbase.PocketBase, modules []model.FeedCollection) model.Events {
|
||||||
Name string `db:"Name" json:"Name"`
|
|
||||||
Course string `db:"course" json:"Course"`
|
|
||||||
}) Events {
|
|
||||||
|
|
||||||
// build query string with name equals elements in modules for dbx query
|
// build query functions with name equals elements in modules for dbx query
|
||||||
|
|
||||||
var queryString string
|
var queryString string
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
@@ -160,7 +103,7 @@ func GetPlanForModules(app *pocketbase.PocketBase, modules []struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var events Events
|
var events model.Events
|
||||||
// get all events from event records in the events collection
|
// get all events from event records in the events collection
|
||||||
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp(queryString)).All(&events)
|
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp(queryString)).All(&events)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -218,59 +161,3 @@ func GetAllModulesDistinct(app *pocketbase.PocketBase) ([]struct {
|
|||||||
}
|
}
|
||||||
return eventArray, nil
|
return eventArray, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Events []*model.Event
|
|
||||||
|
|
||||||
// EmitICal implements the interface for goics
|
|
||||||
func (e Events) EmitICal() goics.Componenter {
|
|
||||||
layout := "2006-01-02 15:04:05 -0700 MST"
|
|
||||||
c := goics.NewComponent()
|
|
||||||
c.SetType("VCALENDAR")
|
|
||||||
c.AddProperty("VERSION", "2.0")
|
|
||||||
c.AddProperty("CALSCAL", "GREGORIAN")
|
|
||||||
c.AddProperty("TZID", "Europe/Berlin")
|
|
||||||
c.AddProperty("X-WR-CALNAME", "HTWK Kalender")
|
|
||||||
c.AddProperty("X-WR-TIMEZONE", "Europe/Berlin")
|
|
||||||
c.AddProperty("X-LIC-LOCATION", "Europe/Berlin")
|
|
||||||
for _, event := range e {
|
|
||||||
s := goics.NewComponent()
|
|
||||||
s.SetType("VEVENT")
|
|
||||||
timeEnd, _ := time.Parse(layout, event.End)
|
|
||||||
timeStart, _ := time.Parse(layout, event.Start)
|
|
||||||
k, v := goics.FormatDateTime("DTEND;TZID=Europe/Berlin", timeEnd)
|
|
||||||
s.AddProperty(k, v)
|
|
||||||
k, v = goics.FormatDateTime("DTSTART;TZID=Europe/Berlin", timeStart)
|
|
||||||
s.AddProperty(k, v)
|
|
||||||
s.AddProperty("SUMMARY", event.Name)
|
|
||||||
s.AddProperty("DESCRIPTION", generateDescription(event))
|
|
||||||
s.AddProperty("LOCATION", event.Rooms)
|
|
||||||
c.AddComponent(s)
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateDescription(event *model.Event) string {
|
|
||||||
var description string
|
|
||||||
|
|
||||||
if !CheckIfOnlyWhitespace(event.Notes) {
|
|
||||||
description += "Notizen: " + event.Notes + "\n"
|
|
||||||
}
|
|
||||||
if !CheckIfOnlyWhitespace(event.Prof) {
|
|
||||||
description += "Prof: " + event.Prof + "\n"
|
|
||||||
}
|
|
||||||
if !CheckIfOnlyWhitespace(event.Course) {
|
|
||||||
description += "Gruppe: " + event.Course + "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
return description
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if course is empty or contains only whitespaces
|
|
||||||
func CheckIfOnlyWhitespace(word string) bool {
|
|
||||||
for _, letter := range word {
|
|
||||||
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
49
backend/service/db/dbRooms.go
Normal file
49
backend/service/db/dbRooms.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase"
|
||||||
|
"htwkalender/model"
|
||||||
|
"htwkalender/service/functions"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRooms(app *pocketbase.PocketBase) []string {
|
||||||
|
|
||||||
|
var events []struct {
|
||||||
|
Rooms string `db:"Rooms" json:"Rooms"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all rooms from event records in the events collection
|
||||||
|
err := app.Dao().DB().Select("Rooms").From("events").All(&events)
|
||||||
|
if err != nil {
|
||||||
|
print("Error while getting rooms from database: ", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomArray []string
|
||||||
|
|
||||||
|
for _, event := range events {
|
||||||
|
var room = strings.Split(event.Rooms, " ")
|
||||||
|
//split functions room by space and add each room to array if it is not already in there
|
||||||
|
for _, r := range room {
|
||||||
|
var text = strings.TrimSpace(r)
|
||||||
|
if !functions.Contains(roomArray, text) && !strings.Contains(text, " ") && len(text) >= 1 {
|
||||||
|
roomArray = append(roomArray, text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roomArray
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string) []model.Event {
|
||||||
|
var events []model.Event
|
||||||
|
|
||||||
|
// get all events from event records in the events collection
|
||||||
|
err := app.Dao().DB().Select("*").From("events").Where(dbx.Like("Rooms", room)).AndWhere(dbx.Like("Start", date)).All(&events)
|
||||||
|
if err != nil {
|
||||||
|
print("Error while getting events from database: ", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return events
|
||||||
|
}
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
"htwkalender/service/db"
|
"htwkalender/service/db"
|
||||||
|
"htwkalender/service/functions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
|
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
|
||||||
@@ -19,9 +20,9 @@ func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, cou
|
|||||||
}
|
}
|
||||||
|
|
||||||
func replaceEmptyEntryInStringArray(modules []string, replacement string) {
|
func replaceEmptyEntryInStringArray(modules []string, replacement string) {
|
||||||
//replace empty string with "Sonderveranstaltungen"
|
//replace empty functions with "Sonderveranstaltungen"
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
if db.CheckIfOnlyWhitespace(module) {
|
if functions.CheckIfOnlyWhitespace(module) {
|
||||||
modules[i] = replacement
|
modules[i] = replacement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,9 +32,9 @@ func replaceEmptyEntry(modules []struct {
|
|||||||
Name string
|
Name string
|
||||||
Course string
|
Course string
|
||||||
}, replacement string) {
|
}, replacement string) {
|
||||||
//replace empty string with "Sonderveranstaltungen"
|
//replace empty functions with "Sonderveranstaltungen"
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
if db.CheckIfOnlyWhitespace(module.Name) {
|
if functions.CheckIfOnlyWhitespace(module.Name) {
|
||||||
modules[i].Name = replacement
|
modules[i].Name = replacement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -118,7 +118,7 @@ func convertWeeksToDates(events []model.Event, semester string, year string) []m
|
|||||||
|
|
||||||
func addTimeToDate(date time.Time, timeString string) time.Time {
|
func addTimeToDate(date time.Time, timeString string) time.Time {
|
||||||
europeTime, _ := time.LoadLocation("Europe/Berlin")
|
europeTime, _ := time.LoadLocation("Europe/Berlin")
|
||||||
//convert time string to time
|
//convert time functions to time
|
||||||
timeParts := strings.Split(timeString, ":")
|
timeParts := strings.Split(timeString, ":")
|
||||||
hour, _ := strconv.Atoi(timeParts[0])
|
hour, _ := strconv.Atoi(timeParts[0])
|
||||||
minute, _ := strconv.Atoi(timeParts[1])
|
minute, _ := strconv.Atoi(timeParts[1])
|
||||||
|
22
backend/service/functions/string.go
Normal file
22
backend/service/functions/string.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package functions
|
||||||
|
|
||||||
|
import "unicode"
|
||||||
|
|
||||||
|
// check if course is empty or contains only whitespaces
|
||||||
|
func CheckIfOnlyWhitespace(word string) bool {
|
||||||
|
for _, letter := range word {
|
||||||
|
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func Contains(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
"github.com/pocketbase/pocketbase/apis"
|
"github.com/pocketbase/pocketbase/apis"
|
||||||
model "htwkalender/model"
|
"htwkalender/model"
|
||||||
db "htwkalender/service/db"
|
"htwkalender/service/db"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -28,10 +28,7 @@ func Feed(c echo.Context, app *pocketbase.PocketBase, token string) error {
|
|||||||
|
|
||||||
created, _ := time.Parse(layout, feed.Created)
|
created, _ := time.Parse(layout, feed.Created)
|
||||||
|
|
||||||
var modules []struct {
|
var modules []model.FeedCollection
|
||||||
Name string `db:"Name" json:"Name"`
|
|
||||||
Course string `db:"course" json:"Course"`
|
|
||||||
}
|
|
||||||
_ = json.Unmarshal([]byte(feed.Modules), &modules)
|
_ = json.Unmarshal([]byte(feed.Modules), &modules)
|
||||||
if created.Add(time.Hour * 265).Before(time.Now()) {
|
if created.Add(time.Hour * 265).Before(time.Now()) {
|
||||||
newFeed, err := createFeedForToken(app, modules)
|
newFeed, err := createFeedForToken(app, modules)
|
||||||
@@ -50,30 +47,26 @@ func Feed(c echo.Context, app *pocketbase.PocketBase, token string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFeedForToken(app *pocketbase.PocketBase, modules []struct {
|
func createFeedForToken(app *pocketbase.PocketBase, modules []model.FeedCollection) (*model.FeedModel, error) {
|
||||||
Name string `db:"Name" json:"Name"`
|
|
||||||
Course string `db:"course" json:"Course"`
|
|
||||||
}) (*model.FeedModel, error) {
|
|
||||||
res := db.GetPlanForModules(app, modules)
|
res := db.GetPlanForModules(app, modules)
|
||||||
b := bytes.Buffer{}
|
b := bytes.Buffer{}
|
||||||
goics.NewICalEncode(&b).Encode(res)
|
goics.NewICalEncode(&b).Encode(IcalModel{Events: res, Mapping: modules})
|
||||||
feed := &model.FeedModel{Content: b.String(), ExpiresAt: time.Now().Add(expirationTime)}
|
feed := &model.FeedModel{Content: b.String(), ExpiresAt: time.Now().Add(expirationTime)}
|
||||||
return feed, nil
|
return feed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSuccess(message string, w http.ResponseWriter) {
|
func writeSuccess(message string, w http.ResponseWriter) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(message))
|
_, err := w.Write([]byte(message))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateIndividualFeed(c echo.Context, app *pocketbase.PocketBase) error {
|
func CreateIndividualFeed(c echo.Context, app *pocketbase.PocketBase) error {
|
||||||
|
|
||||||
// read json from request body
|
// read json from request body
|
||||||
var modules []struct {
|
var modules []model.FeedCollection
|
||||||
Name string `db:"Name" json:"Name"`
|
|
||||||
Course string `db:"course" json:"Course"`
|
|
||||||
}
|
|
||||||
|
|
||||||
requestBodyBytes, err := io.ReadAll(c.Request().Body)
|
requestBodyBytes, err := io.ReadAll(c.Request().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apis.NewApiError(400, "Could not bind request body", err)
|
return apis.NewApiError(400, "Could not bind request body", err)
|
||||||
|
67
backend/service/ical/icalFileGeneration.go
Normal file
67
backend/service/ical/icalFileGeneration.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package ical
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jordic/goics"
|
||||||
|
"htwkalender/model"
|
||||||
|
"htwkalender/service/functions"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// local type for EmitICal function
|
||||||
|
type IcalModel struct {
|
||||||
|
Events model.Events
|
||||||
|
Mapping []model.FeedCollection
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmitICal implements the interface for goics
|
||||||
|
func (icalModel IcalModel) EmitICal() goics.Componenter {
|
||||||
|
layout := "2006-01-02 15:04:05 -0700 MST"
|
||||||
|
c := goics.NewComponent()
|
||||||
|
c.SetType("VCALENDAR")
|
||||||
|
c.AddProperty("VERSION", "2.0")
|
||||||
|
c.AddProperty("CALSCAL", "GREGORIAN")
|
||||||
|
c.AddProperty("TZID", "Europe/Berlin")
|
||||||
|
c.AddProperty("X-WR-CALNAME", "HTWK Kalender")
|
||||||
|
c.AddProperty("X-WR-TIMEZONE", "Europe/Berlin")
|
||||||
|
c.AddProperty("X-LIC-LOCATION", "Europe/Berlin")
|
||||||
|
for _, event := range icalModel.Events {
|
||||||
|
s := goics.NewComponent()
|
||||||
|
s.SetType("VEVENT")
|
||||||
|
timeEnd, _ := time.Parse(layout, event.End)
|
||||||
|
timeStart, _ := time.Parse(layout, event.Start)
|
||||||
|
k, v := goics.FormatDateTime("DTEND;TZID=Europe/Berlin", timeEnd)
|
||||||
|
s.AddProperty(k, v)
|
||||||
|
k, v = goics.FormatDateTime("DTSTART;TZID=Europe/Berlin", timeStart)
|
||||||
|
s.AddProperty(k, v)
|
||||||
|
s.AddProperty("SUMMARY", replaceNameIfUserDefined(event.Name, icalModel.Mapping))
|
||||||
|
s.AddProperty("DESCRIPTION", generateDescription(event))
|
||||||
|
s.AddProperty("LOCATION", event.Rooms)
|
||||||
|
c.AddComponent(s)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func replaceNameIfUserDefined(name string, mapping []model.FeedCollection) string {
|
||||||
|
for _, mapEntry := range mapping {
|
||||||
|
if mapEntry.Name == name {
|
||||||
|
return mapEntry.UserDefinedName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateDescription(event *model.Event) string {
|
||||||
|
var description string
|
||||||
|
|
||||||
|
if !functions.CheckIfOnlyWhitespace(event.Notes) {
|
||||||
|
description += "Notizen: " + event.Notes + "\n"
|
||||||
|
}
|
||||||
|
if !functions.CheckIfOnlyWhitespace(event.Prof) {
|
||||||
|
description += "Prof: " + event.Prof + "\n"
|
||||||
|
}
|
||||||
|
if !functions.CheckIfOnlyWhitespace(event.Course) {
|
||||||
|
description += "Gruppe: " + event.Course + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return description
|
||||||
|
}
|
@@ -25,7 +25,7 @@ export async function fetchModulesByCourseAndSemester(
|
|||||||
})
|
})
|
||||||
.then((modulesResponse) => {
|
.then((modulesResponse) => {
|
||||||
modulesResponse.forEach((module: string) =>
|
modulesResponse.forEach((module: string) =>
|
||||||
modules.push(new Module(module, course)),
|
modules.push(new Module(module, course, module)),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return modules;
|
return modules;
|
||||||
@@ -38,7 +38,9 @@ export async function fetchAllModules(): Promise<Module[]> {
|
|||||||
return response.json() as Promise<Module[]>;
|
return response.json() as Promise<Module[]>;
|
||||||
})
|
})
|
||||||
.then((responseModules: Module[]) => {
|
.then((responseModules: Module[]) => {
|
||||||
modules = responseModules as Module[];
|
responseModules.forEach((module: Module) => {
|
||||||
|
modules.push(new Module(module.Name, module.Course, module.Name));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
|
@@ -3,9 +3,8 @@ import { ref, Ref } from "vue";
|
|||||||
import { Module } from "../model/module.ts";
|
import { Module } from "../model/module.ts";
|
||||||
import { fetchAllModules } from "../api/fetchCourse.ts";
|
import { fetchAllModules } from "../api/fetchCourse.ts";
|
||||||
import moduleStore from "../store/moduleStore.ts";
|
import moduleStore from "../store/moduleStore.ts";
|
||||||
import { createIndividualFeed } from "../api/createFeed.ts";
|
|
||||||
import { MultiSelectAllChangeEvent } from "primevue/multiselect";
|
import { MultiSelectAllChangeEvent } from "primevue/multiselect";
|
||||||
import tokenStore from "../store/tokenStore.ts";
|
|
||||||
import router from "../router";
|
import router from "../router";
|
||||||
|
|
||||||
const fetchedModules = async () => {
|
const fetchedModules = async () => {
|
||||||
@@ -23,14 +22,12 @@ fetchedModules().then(
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
async function finalStep() {
|
async function nextStep() {
|
||||||
selectedModules.value.forEach((module: Module) => {
|
selectedModules.value.forEach((module: Module) => {
|
||||||
moduleStore().addModule(module);
|
moduleStore().addModule(module);
|
||||||
});
|
});
|
||||||
|
|
||||||
const token: string = await createIndividualFeed(moduleStore().modules);
|
await router.push("/rename-modules");
|
||||||
tokenStore().setToken(token);
|
|
||||||
await router.push("/calendar-link");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const display = (module: Module) => module.Name + " (" + module.Course + ")";
|
const display = (module: Module) => module.Name + " (" + module.Course + ")";
|
||||||
@@ -90,7 +87,7 @@ function selectChange() {
|
|||||||
</MultiSelect>
|
</MultiSelect>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex align-items-center justify-content-center h-4rem m-2">
|
<div class="flex align-items-center justify-content-center h-4rem m-2">
|
||||||
<Button @click="finalStep()"> Create Calendar</Button>
|
<Button @click="nextStep()">Next Step</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
63
frontend/src/components/RenameModules.vue
Normal file
63
frontend/src/components/RenameModules.vue
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import moduleStore from "../store/moduleStore.ts";
|
||||||
|
import { createIndividualFeed } from "../api/createFeed.ts";
|
||||||
|
import router from "../router";
|
||||||
|
import tokenStore from "../store/tokenStore.ts";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
const tableData = ref(moduleStore().modules.map((module) => {
|
||||||
|
return {
|
||||||
|
Course: module.Course,
|
||||||
|
Module: module,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns = ref([
|
||||||
|
{ field: 'Course', header: 'Course' },
|
||||||
|
{ field: 'Module', header: 'Module' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
async function finalStep() {
|
||||||
|
const token: string = await createIndividualFeed(moduleStore().modules);
|
||||||
|
tokenStore().setToken(token);
|
||||||
|
await router.push("/calendar-link");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-column">
|
||||||
|
<div class="flex align-items-center justify-content-center h-4rem m-2">
|
||||||
|
<h3>
|
||||||
|
Rename your selected Modules to your liking.
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card flex align-items-center justify-content-center m-2">
|
||||||
|
<DataTable :value="tableData" editMode="cell" tableClass="editable-cells-table" responsiveLayout="scroll">
|
||||||
|
<Column v-for="col of columns" :key="col.field" :field="col.field" :header="col.header">
|
||||||
|
<template #body="{ data, field }" >
|
||||||
|
<div>{{ field === 'Module' ? data[field].UserDefinedName : data[field] }}</div>
|
||||||
|
</template>
|
||||||
|
<template #editor="{ data, field }">
|
||||||
|
<template v-if="field !== 'Module'">
|
||||||
|
<div>{{ data[field] }}</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<InputText class="w-full" v-model="data[field].UserDefinedName" autofocus />
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
</DataTable>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex align-items-center justify-content-center h-4rem m-2">
|
||||||
|
<Button @click="finalStep()">Next Step</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
@@ -21,6 +21,8 @@ import ToastService from "primevue/toastservice";
|
|||||||
import Toast from "primevue/toast";
|
import Toast from "primevue/toast";
|
||||||
import Accordion from 'primevue/accordion';
|
import Accordion from 'primevue/accordion';
|
||||||
import AccordionTab from 'primevue/accordiontab';
|
import AccordionTab from 'primevue/accordiontab';
|
||||||
|
import DataTable from "primevue/datatable";
|
||||||
|
import Column from "primevue/column";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
@@ -42,4 +44,6 @@ app.component("MultiSelect", MultiSelect);
|
|||||||
app.component("Toast", Toast);
|
app.component("Toast", Toast);
|
||||||
app.component("Accordion", Accordion);
|
app.component("Accordion", Accordion);
|
||||||
app.component("AccordionTab", AccordionTab);
|
app.component("AccordionTab", AccordionTab);
|
||||||
|
app.component("DataTable", DataTable);
|
||||||
|
app.component("Column", Column);
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
|
@@ -2,5 +2,6 @@ export class Module {
|
|||||||
constructor(
|
constructor(
|
||||||
public Name: string,
|
public Name: string,
|
||||||
public Course: string,
|
public Course: string,
|
||||||
|
public UserDefinedName: string,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import AdditionalModules from "../components/AdditionalModules.vue";
|
|||||||
import CalendarLink from "../components/CalendarLink.vue";
|
import CalendarLink from "../components/CalendarLink.vue";
|
||||||
import Impress from "../components/Impress.vue";
|
import Impress from "../components/Impress.vue";
|
||||||
import PrivacyPolicy from "../components/PrivacyPolicy.vue";
|
import PrivacyPolicy from "../components/PrivacyPolicy.vue";
|
||||||
|
import RenameModules from "../components/RenameModules.vue";
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
@@ -39,6 +40,11 @@ const router = createRouter({
|
|||||||
name: "impress",
|
name: "impress",
|
||||||
component: Impress,
|
component: Impress,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/rename-modules",
|
||||||
|
name: "rename-modules",
|
||||||
|
component: RenameModules,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/:catchAll(.*)",
|
path: "/:catchAll(.*)",
|
||||||
redirect: "/",
|
redirect: "/",
|
||||||
|
Reference in New Issue
Block a user