diff --git a/cms/src/lib/components/CalendarEvent.ts b/cms/src/lib/components/CalendarEvent.ts
deleted file mode 100644
index d947809..0000000
--- a/cms/src/lib/components/CalendarEvent.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export interface CalendarEvent {
- id:string;
- title:string;
- start:Date|string;
- end?:Date|string;
- url?:string;
- backgroundColor?:string;
-}
\ No newline at end of file
diff --git a/cms/src/lib/components/Exam.ts b/cms/src/lib/components/Exam.ts
deleted file mode 100644
index 806a3ff..0000000
--- a/cms/src/lib/components/Exam.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export interface Exam {
- id:string;
- title:string;
- start?:Date|string;
- end?:Date|string;
- exam_date?:Date|string;
- announcement_date?:Date|string;
- category_id?:string
- category?:string
- img?:string;
-}
\ No newline at end of file
diff --git a/cms/src/lib/data/CMSDataType.ts b/cms/src/lib/data/CMSDataType.ts
new file mode 100644
index 0000000..2ae720b
--- /dev/null
+++ b/cms/src/lib/data/CMSDataType.ts
@@ -0,0 +1,28 @@
+export interface Exam {
+ id:string;
+ title:string;
+ date:string;
+ start?:Date|string;
+ end?:Date|string;
+ exam_date?:Date|string;
+ announcement_date?:Date|string;
+ category_id?:string
+ category?:string
+ img?:string;
+}
+export interface CalendarEvent {
+ id:string;
+ title:string;
+ start:Date|string;
+ end?:Date|string;
+ url?:string;
+ backgroundColor?:string;
+}
+export interface CMSInfo{
+ logo_url:string;
+ organization:string;
+ supervised:Date|string;
+ address:Date|string;
+ divisions:{title:string,url:string}[];
+ institutes:{title:string,url:string}[];
+}
diff --git a/cms/src/routes/+layout.server.ts b/cms/src/routes/+layout.server.ts
new file mode 100644
index 0000000..509c6e0
--- /dev/null
+++ b/cms/src/routes/+layout.server.ts
@@ -0,0 +1,14 @@
+
+import { error } from '@sveltejs/kit';
+import type { PageServerLoad } from './$types'
+export const load: PageServerLoad = async ({fetch}) => {
+ const res = await fetch("/api/info")
+ if(res.ok){
+ const info = await res.json()
+ return info
+ }else{
+ throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของเวปได้');
+ }
+
+
+}
\ No newline at end of file
diff --git a/cms/src/routes/+layout.svelte b/cms/src/routes/+layout.svelte
index 28ac727..3748d87 100644
--- a/cms/src/routes/+layout.svelte
+++ b/cms/src/routes/+layout.svelte
@@ -1,7 +1,15 @@
-
diff --git a/cms/src/routes/+page.server.ts b/cms/src/routes/+page.server.ts
index 172c500..2c5506b 100644
--- a/cms/src/routes/+page.server.ts
+++ b/cms/src/routes/+page.server.ts
@@ -1,7 +1,8 @@
//import content from "$lib/data/content/home.html?raw"
//import { getQualifyExams,getCompetitiveExams } from '$lib/data/info';
import type { PageServerLoad } from './$types';
-import type {Exam} from '$lib/components/Exam'
+import type {Exam} from '$lib/components/Exam'
+import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => {
let qualify_exams: Exam[] = []
let competitive_exams: Exam[] = []
@@ -13,10 +14,16 @@ export const load: PageServerLoad = async ({fetch}) => {
res = await fetch("/api/qualifying")
if(res.ok){
qualify_exams = await res.json()
+ qualify_exams.forEach((e)=>{
+ e.start? dayjs(e.start).format("DD MMM BBBB"):""
+ })
}
res = await fetch("/api/competitive")
if(res.ok){
competitive_exams = await res.json()
+ competitive_exams.forEach((e)=>{
+ e.start? dayjs(e.start).format("DD MMM BBBB"):""
+ })
}
return { content , qualify_exams,competitive_exams };
};
diff --git a/cms/src/routes/api/info/+server.ts b/cms/src/routes/api/info/+server.ts
index 5787096..cdaf637 100644
--- a/cms/src/routes/api/info/+server.ts
+++ b/cms/src/routes/api/info/+server.ts
@@ -1,8 +1,9 @@
import ver from "$lib/ver.json"
import {json} from '@sveltejs/kit'
+import info from "$lib/data/info.json"
import type { RequestHandler } from './$types'
export const GET: RequestHandler = async () => {
const version = ver.version
const builddate = ver.builddate
- return json({version,builddate})
+ return json({...info,version,builddate})
}
\ No newline at end of file
diff --git a/cms/src/routes/competitive/+page.server.ts b/cms/src/routes/competitive/+page.server.ts
index 09a54e8..8be360a 100644
--- a/cms/src/routes/competitive/+page.server.ts
+++ b/cms/src/routes/competitive/+page.server.ts
@@ -1,7 +1,6 @@
import type { PageServerLoad } from './$types'
-import type {CalendarEvent} from '$lib/components/CalendarEvent'
-import type {Exam} from '$lib/components/Exam'
-
+import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
+import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => {
let content = ""
let exams:Exam[] = []
@@ -16,8 +15,19 @@ export const load: PageServerLoad = async ({fetch}) => {
}
const events:CalendarEvent[]=[]
- exams.forEach(({id,title,start})=>{
- const backgroundColor ="#9999FF"
+ exams.forEach((e)=>{
+ if(!e.start){
+ e.date=""
+ return
+ }
+ e.date= dayjs(e.start).format("DD MMM BBBB")
+
+ const {id,title,start,category_id} = e
+
+ let backgroundColor ="#9999FF"
+ if(category_id)
+ backgroundColor ="#99FFEE"
+
const url = "/competitive/"+id
events.push({id,title,start,url,backgroundColor})
})
diff --git a/cms/src/routes/competitive/[id]/+page.server.ts b/cms/src/routes/competitive/[id]/+page.server.ts
index ed61113..8cba08a 100644
--- a/cms/src/routes/competitive/[id]/+page.server.ts
+++ b/cms/src/routes/competitive/[id]/+page.server.ts
@@ -1,18 +1,16 @@
-
-import type { PageServerLoad } from './$types'
+//import type {Exam} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'
-import exams from "$lib/data/competitive-exam.json"
-export const load: PageServerLoad = async ({params}) => {
+import type { PageServerLoad } from './$types'
+export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+""
- //const exams = await getCompetitiveExams()
- const post = exams.find((q)=>{
- return q.id===id
- })
-
- if(post)
- return post
- else
- throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"})
-
+ const res = await fetch("/api/compettive/"+id)
+ if(res.status==404){
+ throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
+ }
+ if(!res.ok){
+ throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
+ }
+ const post = await res.json()
+ return post
}
diff --git a/cms/src/routes/qualifying/+page.server.ts b/cms/src/routes/qualifying/+page.server.ts
index 51e28e2..9e837ec 100644
--- a/cms/src/routes/qualifying/+page.server.ts
+++ b/cms/src/routes/qualifying/+page.server.ts
@@ -1,6 +1,8 @@
+
+import type {CalendarEvent} from '$lib/data/CMSDataType'
+import type {Exam} from '$lib/data/CMSDataType'
+import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
-import type {CalendarEvent} from '$lib/components/CalendarEvent'
-import type {Exam} from '$lib/components/Exam'
export const load: PageServerLoad = async ({fetch}) => {
let content = ""
let exams:Exam[] = []
@@ -13,23 +15,36 @@ export const load: PageServerLoad = async ({fetch}) => {
exams = await res.json()
}
const events:CalendarEvent[]=[]
- exams.forEach(({id,title,start,institute_id})=>{
+ exams.forEach((e)=>{
+ if(!e.start){
+ e.date=""
+ return
+ }
+ e.date= dayjs(e.start).format("DD MMM BBBB")
+ const {id,title,start,end,category_id} = e
let backgroundColor =""
- switch (institute_id) {
- case 1:
+ switch (category_id) {
+ case "1":
backgroundColor="rgba(251,64,75,.2)"
break;
- case 2:
+ case "2":
backgroundColor="#23ccef"
break;
- case 3:
+ case "3":
backgroundColor="rgba(68,125,247,.2)"
break;
default:
break;
}
const url = "/qualifying/"+id
- events.push({id,title,start,url,backgroundColor})
+ events.push({id,title,start,end,url,backgroundColor})
+ if(e.exam_date){
+ events.push({id,"title":"สอบ","start":e.exam_date,url,backgroundColor})
+ }
+ if(e.announcement_date){
+ events.push({id,"title":"ผลสอบสอบ","start":e.announcement_date,url,backgroundColor})
+ }
+
})
return {exams,events,content}
}
diff --git a/cms/src/routes/qualifying/+page.svelte b/cms/src/routes/qualifying/+page.svelte
index d2cfee1..a524f2f 100644
--- a/cms/src/routes/qualifying/+page.svelte
+++ b/cms/src/routes/qualifying/+page.svelte
@@ -53,7 +53,7 @@
| วันที่ |
การสอบ |
- หน่วยงาน |
+ ประเภท |
@@ -61,7 +61,7 @@
| {exam.date} |
{exam.title} |
- {exam.institute} |
+ {exam.category} |
{/each}
diff --git a/cms/src/routes/qualifying/[id]/+page.server.ts b/cms/src/routes/qualifying/[id]/+page.server.ts
index 56f1514..69f64ae 100644
--- a/cms/src/routes/qualifying/[id]/+page.server.ts
+++ b/cms/src/routes/qualifying/[id]/+page.server.ts
@@ -1,17 +1,16 @@
-
-import type { PageServerLoad } from './$types'
+//import type {Exam} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'
-import exams from "$lib/data/qualify-exam.json"
-export const load: PageServerLoad = async ({params}) => {
+import type { PageServerLoad } from './$types'
+export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+""
- const post = exams.find((q)=>{
- return q.id===id
- })
-
- if(post)
- return post
- else
- throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"})
-
+ const res = await fetch("/api/qualifying/"+id)
+ if(res.status==404){
+ throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
+ }
+ if(!res.ok){
+ throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
+ }
+ const post = await res.json()
+ return post
}
diff --git a/cms/src/routes/qualifying/[id]/+page.svelte b/cms/src/routes/qualifying/[id]/+page.svelte
index b4c07c8..7814947 100644
--- a/cms/src/routes/qualifying/[id]/+page.svelte
+++ b/cms/src/routes/qualifying/[id]/+page.svelte
@@ -1,9 +1,6 @@