queryList for Admin

This commit is contained in:
PawelJa 2019-01-11 17:56:26 +01:00
parent 8e3024e8b1
commit ccc22607eb
24 changed files with 1565 additions and 375 deletions

View File

@ -3,30 +3,20 @@
<component name="ChangeListManager">
<list default="true" id="baac0fea-ba77-4412-8e4a-c4ee1e16e324" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/alghoritms.go" beforeDir="false" afterPath="$PROJECT_DIR$/alghoritms.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/calendarController.go" beforeDir="false" afterPath="$PROJECT_DIR$/calendarController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/models.go" beforeDir="false" afterPath="$PROJECT_DIR$/models.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/router.go" beforeDir="false" afterPath="$PROJECT_DIR$/router.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes.go" beforeDir="false" afterPath="$PROJECT_DIR$/routes.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/queriesController.go" beforeDir="false" afterPath="$PROJECT_DIR$/queriesController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/angular.json" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/angular.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/app.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/app.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/create-query/create-query.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/create-query/create-query.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/app.router.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/app.router.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/admin-menu/admin-menu.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/admin-menu/admin-menu.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/create-query/create-query.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/create-query/create-query.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/edit-term-admin/edit-term-admin.component.css" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/edit-term-admin/edit-term-admin.component.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/edit-term-admin/edit-term-admin.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/edit-term-admin/edit-term-admin.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/edit-term-admin/edit-term-admin.component.spec.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/edit-term-admin/edit-term-admin.component.spec.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/edit-term-admin/edit-term-admin.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/dialogs/edit-term-admin/edit-term-admin.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list-admin/term-list-admin.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list/term-list.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list/term-list.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list/term-list.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/term-list/term-list.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/test/test.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/test/test.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/models/CreateQuery.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/models/Query.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/models/Term.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/models/Term.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/services/term.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/services/term.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/services/termin-admin-service.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/services/termin-admin-service.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/login/login.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/login/login.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/services/query.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/services/query.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt_visio.exe" beforeDir="false" afterPath="$PROJECT_DIR$/szt_visio.exe" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -69,35 +59,37 @@
<session id="2110107836">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="11" />
<entry key="project.closed" value="12" />
<entry key="project.open.time.1" value="1" />
<entry key="project.open.time.10" value="4" />
<entry key="project.open.time.12" value="1" />
<entry key="project.open.time.13" value="1" />
<entry key="project.open.time.14" value="1" />
<entry key="project.open.time.21" value="1" />
<entry key="project.open.time.22" value="1" />
<entry key="project.open.time.7" value="1" />
<entry key="project.open.time.9" value="2" />
<entry key="project.opened" value="11" />
<entry key="project.opened" value="13" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="go" value="9258" />
<entry key="go" value="9583" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Go" value="9258" />
<entry key="Go" value="9583" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="go" value="38" />
<entry key="go" value="42" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Go" value="38" />
<entry key="Go" value="42" />
</counts>
</usages-collector>
<usages-collector id="statistics.go.postfix.template.usages.trigger">
@ -112,8 +104,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="95" selection-start-line="14" selection-start-column="95" selection-end-line="14" selection-end-column="95" />
<state relative-caret-position="320">
<caret line="28" column="58" selection-start-line="28" selection-start-column="58" selection-end-line="28" selection-end-column="58" />
<folding>
<element signature="e#14#128#0" expanded="true" />
</folding>
@ -121,56 +113,20 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/router.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" selection-start-line="2" selection-start-column="2" selection-end-line="18" selection-end-column="3" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/dbConnector.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="24" column="19" selection-start-line="24" selection-start-column="19" selection-end-line="24" selection-end-column="19" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391">
<caret line="23" column="3" selection-start-line="23" selection-start-column="3" selection-end-line="23" selection-end-column="3" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/calendarController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="224" column="70" selection-start-line="224" selection-start-column="70" selection-end-line="224" selection-end-column="70" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/booking.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="473">
<caret line="150" column="1" selection-start-line="79" selection-end-line="150" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/queriesController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="26" column="68" selection-start-line="26" selection-start-column="68" selection-end-line="26" selection-end-column="68" />
<state relative-caret-position="493">
<caret line="65" column="29" selection-start-line="65" selection-start-column="29" selection-end-line="65" selection-end-column="29" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/calendarController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="524">
<caret line="133" column="1" selection-start-line="92" selection-end-line="133" selection-end-column="1" />
</state>
</provider>
</entry>
@ -178,8 +134,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/models.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" column="43" selection-start-line="12" selection-start-column="43" selection-end-line="12" selection-end-column="43" />
<state relative-caret-position="136">
<caret line="8" column="22" selection-start-line="8" selection-start-column="22" selection-end-line="8" selection-end-column="22" />
</state>
</provider>
</entry>
@ -213,15 +169,15 @@
<option value="$PROJECT_DIR$/dbConfig/config.go" />
<option value="$PROJECT_DIR$/dbConnector.go" />
<option value="$PROJECT_DIR$/router/routes.go" />
<option value="$PROJECT_DIR$/alghoritms.go" />
<option value="$PROJECT_DIR$/proba.go" />
<option value="$PROJECT_DIR$/queriesController.go" />
<option value="$PROJECT_DIR$/booking.go" />
<option value="$PROJECT_DIR$/routes.go" />
<option value="$PROJECT_DIR$/router.go" />
<option value="$PROJECT_DIR$/models.go" />
<option value="$PROJECT_DIR$/main.go" />
<option value="$PROJECT_DIR$/alghoritms.go" />
<option value="$PROJECT_DIR$/calendarController.go" />
<option value="$PROJECT_DIR$/main.go" />
<option value="$PROJECT_DIR$/models.go" />
<option value="$PROJECT_DIR$/queriesController.go" />
</list>
</option>
</component>
@ -318,9 +274,9 @@
</recent_temporary>
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
<frame x="-8" y="-8" width="1936" height="1066" extended-state="7" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.28997868" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.29637527" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
@ -364,10 +320,24 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391">
<caret line="23" column="3" selection-start-line="23" selection-start-column="3" selection-end-line="23" selection-end-column="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/alghoritms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="17" column="5" selection-start-line="17" selection-start-column="5" selection-end-line="17" selection-end-column="5" />
<state relative-caret-position="238">
<caret line="19" column="1" selection-start-line="19" selection-start-column="1" selection-end-line="19" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/booking.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="541">
<caret line="150" column="1" selection-start-line="79" selection-end-line="150" selection-end-column="1" />
</state>
</provider>
</entry>
@ -378,27 +348,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/queriesController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="26" column="68" selection-start-line="26" selection-start-column="68" selection-end-line="26" selection-end-column="68" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/models.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" column="43" selection-start-line="12" selection-start-column="43" selection-end-line="12" selection-end-column="43" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/booking.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="473">
<caret line="150" column="1" selection-start-line="79" selection-end-line="150" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/router.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
@ -406,17 +355,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="391">
<caret line="23" column="3" selection-start-line="23" selection-start-column="3" selection-end-line="23" selection-end-column="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="95" selection-start-line="14" selection-start-column="95" selection-end-line="14" selection-end-column="95" />
<state relative-caret-position="320">
<caret line="28" column="58" selection-start-line="28" selection-start-column="58" selection-end-line="28" selection-end-column="58" />
<folding>
<element signature="e#14#128#0" expanded="true" />
</folding>
@ -425,8 +367,22 @@
</entry>
<entry file="file://$PROJECT_DIR$/calendarController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="224" column="70" selection-start-line="224" selection-start-column="70" selection-end-line="224" selection-end-column="70" />
<state relative-caret-position="524">
<caret line="133" column="1" selection-start-line="92" selection-end-line="133" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/models.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="22" selection-start-line="8" selection-start-column="22" selection-end-line="8" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/queriesController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493">
<caret line="65" column="29" selection-start-line="65" selection-start-column="29" selection-end-line="65" selection-end-column="29" />
</state>
</provider>
</entry>

View File

@ -2,18 +2,19 @@ package main
import (
"fmt"
"net/http"
"strconv"
"time"
)
func daysIn(m int, year int) {
func daysIn(m int, year int, w http.ResponseWriter) {
var data string
dni := time.Date(year, time.Month(m+1),0,0,0,0,0,time.UTC)
for i := 1; i <= dni.Day(); i++ {
data = strconv.Itoa(year) + "-" + strconv.Itoa(int(m)) + "-" + strconv.Itoa(i)
fmt.Println("data: ", data)
addRow(data)
addRow(data, w)
}
}

View File

@ -10,41 +10,49 @@ import (
)
func newTerm(w http.ResponseWriter, req *http.Request) {
log.Println("weszlo")
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
log.Println(string(body))
var term term_struct
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
for i := 0; i < len(term.Months); i++ {
daysIn(term.Months[i], term.Year)
daysIn(term.Months[i], term.Year, w)
}
}
func addRow(data string) {
func addRow(data string, w http.ResponseWriter) {
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO calendar (date, status, contractNo) VALUES ( $1, 'available', '');")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close() // danger!
for i := 0; i < 1; i++ {
_, err = stmt.Exec(data)
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
}
@ -63,7 +71,6 @@ func getTerms2(w http.ResponseWriter, r *http.Request) {
for rows.Next() {
term := Term{}
err = rows.Scan(
&term.Id,
&term.Date,
&term.Status,
&term.Contractno,
@ -90,29 +97,32 @@ func getTerms(w http.ResponseWriter, r *http.Request) {
terms := []Term{}
stmt, err := db.Prepare("SELECT * FROM calendar WHERE EXTRACT(MONTH FROM date) = $1 AND EXTRACT(YEAR FROM date) = $2 ORDER BY date ASC;")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
rows, err := stmt.Query(vars["month"], vars["year"])
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer rows.Close()
for rows.Next() {
term := Term{}
err = rows.Scan(
&term.Id,
&term.Date,
&term.Status,
&term.Contractno,
)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
terms = append(terms, term)
}
if err = rows.Err(); err != nil {
log.Fatal(err)
http.Error(w, "błąd danych", 500)
return
}
out, err := json.Marshal(terms)
if err != nil {
@ -127,25 +137,29 @@ func deleteTerm(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
log.Println(string(body))
var term Term
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
fmt.Println(term)
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer tx.Rollback()
stmt, err := tx.Prepare("DELETE FROM contracts WHERE date=$1;")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
@ -167,12 +181,14 @@ func deleteTerm(w http.ResponseWriter, req *http.Request) {
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer tx.Rollback()
stmt, err := tx.Prepare("UPDATE calendar SET status=$1, contractno=$2 WHERE date=$3;")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
@ -198,25 +214,29 @@ func putTerm(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
log.Println(string(body))
var term Term
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
fmt.Println(term)
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO contracts (date, status, contractno) VALUES ($1, $2, $3) ON CONFLICT (date) DO UPDATE SET status=$2, contractno=$3;")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
@ -238,12 +258,14 @@ func putTerm(w http.ResponseWriter, req *http.Request) {
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer tx.Rollback()
stmt, err := tx.Prepare("UPDATE calendar SET status=$1, contractno=$2 WHERE date=$3;")
if err != nil {
log.Fatal(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
@ -271,7 +293,8 @@ func postTest(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
fmt.Println("postTest")
log.Println(string(body));
@ -284,7 +307,8 @@ func deleteTest(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
http.Error(w, "błąd zapisu danych", 500)
return
}
fmt.Println("deleteTest");
log.Println(string(body));

View File

@ -21,10 +21,12 @@ func main() {
router:=mux.NewRouter()
router.HandleFunc("/term/{year}/{month}", getTerms).Methods("GET", "OPTIONS")
router.HandleFunc("/term", newTerm).Methods("POST", "OPTIONS")
router.HandleFunc("/term", deleteTerm).Methods("DELETE", "OPTIONS")
router.HandleFunc("/term", putTerm).Methods("PUT", "OPTIONS")
router.HandleFunc("/query", newQuery).Methods("POST", "OPTIONS")
router.HandleFunc("/query", getQueryList).Methods("GET", "OPTIONS")
router.HandleFunc("/test", postTest).Methods("POST", "OPTIONS")

View File

@ -5,7 +5,8 @@ type term_struct struct {
Year int `json:"year"`
}
type NewQuery struct {
type Query struct {
Id int `json:"id"`
Startdate string `json:"startdate"`
Enddate string `json:"enddate"`
Location string `json:"location"`
@ -17,15 +18,7 @@ type NewQuery struct {
Questiondate string `json:"questiondate"`
}
//type Term struct {
// id int `json:"id"`
// date string `json:"date"`
// status string `json:"status"`
// contractno string `json:"contractno"`
//}
type Term struct {
Id int `json:"id"`
Date string `json:"date"`
Status string `json:"status"`
Contractno string `json:"contractno"`

View File

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
@ -13,7 +14,7 @@ func newQuery(w http.ResponseWriter, req *http.Request) {
panic(err)
}
log.Println(string(body))
var query NewQuery
var query Query
err = json.Unmarshal(body, &query)
if err != nil {
panic(err)
@ -40,4 +41,53 @@ func newQuery(w http.ResponseWriter, req *http.Request) {
if err != nil {
log.Fatal(err)
}
}
func getQueryList(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
queryList := []Query{}
stmt, err := db.Prepare("SELECT * FROM queries ORDER BY questiondate DESC")
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
defer stmt.Close()
rows, err := stmt.Query()
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
defer rows.Close()
for rows.Next() {
query := Query{}
err = rows.Scan(
&query.Id,
&query.Startdate,
&query.Enddate,
&query.Location,
&query.Description,
&query.Contactperson,
&query.Contactno,
&query.Email,
&query.Status,
&query.Questiondate,
)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
queryList = append(queryList, query)
}
if err = rows.Err(); err != nil {
http.Error(w, "błąd danych", 500)
return
}
out, err := json.Marshal(queryList)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprint(w, string(out))
}

View File

@ -33,7 +33,7 @@
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
"with": "src/environments/environment.ts"
}
],
"optimization": true,

File diff suppressed because it is too large Load Diff

View File

@ -19,11 +19,15 @@
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/material": "^7.1.0",
"@angular/material-moment-adapter": "^7.2.1",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"angular-moment": "^1.3.0",
"angularfire2": "^5.1.1",
"bootstrap": "^4.2.1",
"core-js": "^2.5.4",
"firebase": "^5.7.2",
"hammerjs": "^2.0.8",
"primeicons": "^1.0.0",
"primeng": "^7.0.3",
@ -31,7 +35,7 @@
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.11.4",
"@angular-devkit/build-angular": "^0.12.1",
"@angular/cli": "~7.0.6",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",

View File

@ -1,5 +1,5 @@
import {BrowserModule} from '@angular/platform-browser';
import {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
import {CUSTOM_ELEMENTS_SCHEMA, LOCALE_ID, NgModule} from '@angular/core';
import {MAT_DATE_LOCALE} from '@angular/material';
import {AppComponent} from './app.component';
import {AddTermsComponent} from './components/add-terms/add-terms.component';
@ -20,6 +20,10 @@ import {AngularFireAuthModule} from 'angularfire2/auth';
import {LoginComponent} from './components/login/login.component';
import {AuthService} from './services/auth.service';
import {AuthGuardsService} from './services/auth-guards.service';
import {registerLocaleData} from '@angular/common';
import pl from '@angular/common/locales/pl';
import {QueryDetailesComponent} from './components/dialogs/query-detailes/query-detailes.component';
import {QueriesListAdminComponent} from './components/queries-list-admin/queries-list-admin.component';
const config = {
apiKey: 'AIzaSyBuOHXooBv4bsWWgEZxd7Y86TrxkrbYZIU',
@ -30,6 +34,8 @@ const config = {
messagingSenderId: '298719712363'
};
registerLocaleData(pl);
@NgModule({
declarations: [
AppComponent,
@ -41,7 +47,9 @@ const config = {
AdminMenuComponent,
TermListAdminComponent,
EditTermAdminComponent,
LoginComponent
LoginComponent,
QueriesListAdminComponent,
QueryDetailesComponent
],
imports: [
BrowserModule,
@ -54,8 +62,8 @@ const config = {
AngularFireModule.initializeApp(config),
AngularFireAuthModule
],
entryComponents: [CreateQueryComponent, EditTermAdminComponent],
providers: [AuthService, AuthGuardsService, {provide: MAT_DATE_LOCALE, useValue: 'pl-PL'}],
entryComponents: [CreateQueryComponent, EditTermAdminComponent, QueryDetailesComponent],
providers: [AuthService, AuthGuardsService, {provide: MAT_DATE_LOCALE, useValue: 'pl-PL'}, {provide: LOCALE_ID, useValue: 'pl'}],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

View File

@ -7,6 +7,7 @@ import {TermListAdminComponent} from './components/term-list-admin/term-list-adm
import {NgModule} from '@angular/core';
import {LoginComponent} from './components/login/login.component';
import {AuthGuardsService} from './services/auth-guards.service';
import {QueriesListAdminComponent} from './components/queries-list-admin/queries-list-admin.component';
export const appRoutes: Routes = [
{
@ -26,6 +27,10 @@ export const appRoutes: Routes = [
{
path: 'term-list-admin',
component: TermListAdminComponent
},
{
path: 'queries',
component: QueriesListAdminComponent
}
]
},

View File

@ -1,6 +1,6 @@
<a routerLink="add-term">Dodaj terminy</a>
<a routerLink="term-list-admin">Terminy</a>
<a routerLink="test">Test</a>
<a routerLink="queries">Zapytania</a>
<br>
<br>
<router-outlet></router-outlet>

View File

@ -3,10 +3,15 @@ import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Query} from '../../../models/Query';
import {QueryService} from '../../../services/query.service';
// @ts-ignore
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
import * as _moment from 'moment';
// tslint:disable-next-line:no-duplicate-imports
// @ts-ignore
import {default as _rollupMoment} from 'moment';
const moment = _rollupMoment || _moment;
export const MY_FORMATS = {
parse: {
@ -28,6 +33,7 @@ export const MY_FORMATS = {
// `MomentDateAdapter` can be automatically provided by importing `MomentDateModule` in your
// application's root module. We provide it at the component level here, due to limitations of
// our example generation script.
// @ts-ignore
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
@ -72,10 +78,10 @@ export class CreateQueryComponent {
this.newQuery.email = this.form.controls.email.value;
console.log('wysylam ', this.newQuery);
this.queryService.createQuery(this.newQuery).subscribe( x => {
this.openSnackBar('Rezerwacja wysłana !');
this.onAbort();
},
this.queryService.createQuery(this.newQuery).subscribe(x => {
this.openSnackBar('Rezerwacja wysłana !');
this.onAbort();
},
error => this.openSnackBar('Coś poszło nie tak.. Spróbuj ponownie'));
}

View File

@ -0,0 +1,59 @@
<div class="container">
<div class="row">
<div class="col-sm-3">
Data zapytania
</div>
<div class="col-sm-9">
{{ data.questiondate | date: 'dd - MM - yyyy' }}
</div>
<div class="col-sm-3">
Osoba kontaktowa
</div>
<div class="col-sm-9">
{{ data.contactperson }}
</div>
<div class="col-sm-3">
Nr telefonu
</div>
<div class="col-sm-9">
{{ data.contactno}}
</div>
<div class="col-sm-3">
Email
</div>
<div class="col-sm-9">
{{ data.email }}
</div>
<div class="col-sm-3">
Data początkowa
</div>
<div class="col-sm-9">
{{ data.startdate | date: 'dd - MM - yyyy' }}
</div>
<div class="col-sm-3">
Data końcowa
</div>
<div class="col-sm-9">
{{ data.enddate | date: 'dd - MM - yyyy' }}
</div>
<div class="col-sm-3">
Lokalizacja
</div>
<div class="col-sm-9">
{{ data.questiondate | date: 'dd - MM - yyyy' }}
</div>
<div class="col-sm-3">
Treść
</div>
<div class="col-sm-9">
{{ data.description }}
</div>
</div>
<button class="btn btn-sm btn-info" (click)="onNoClick()">Zamknij</button>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { QueryDetailesComponent } from './query-detailes.component';
describe('QueryDetailesComponent', () => {
let component: QueryDetailesComponent;
let fixture: ComponentFixture<QueryDetailesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ QueryDetailesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(QueryDetailesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,23 @@
import {Component, Inject, OnInit} from '@angular/core';
import {Query} from '../../../models/Query';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material';
import {FormGroup} from '@angular/forms';
@Component({
selector: 'app-query-detailes',
templateUrl: './query-detailes.component.html',
styleUrls: ['./query-detailes.component.css']
})
export class QueryDetailesComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<QueryDetailesComponent>, @Inject(MAT_DIALOG_DATA) public data: Query) {
}
ngOnInit() {
}
onNoClick(): void {
this.dialogRef.close();
}
}

View File

@ -1,17 +1,31 @@
<!--&lt;!&ndash;<div *ngIf="authService.user">&ndash;&gt;-->
<!--<form #formData="ngForm">-->
<!--<label>Email</label>-->
<!--<input ngModel type="email" name="email" required>-->
<!--<br>-->
<!--<label>Hasło</label>-->
<!--<input ngModel type="password" name="password" required>-->
<!--<button (click)="login(formData)" [disabled]="formData.invalid">Zaloguj</button>-->
<!--<button (click)="register()">Rejestracja</button>-->
<!--</form>-->
<!--&lt;!&ndash;</div>&ndash;&gt;-->
<!--<div *ngIf="authService.user">-->
<form #formData="ngForm">
<label>Email</label>
<input ngModel type="email" name="email" required>
<br>
<label>Hasło</label>
<input ngModel type="password" name="password" required>
<button (click)="login(formData)" [disabled]="formData.invalid">Zaloguj</button>
<button (click)="register()">Rejestracja</button>
</form>
<!--<button (click)="logout()">Wyloguj</button>-->
<!--</div>-->
<div *ngIf="authService.user">
<button (click)="logout()">Wyloguj</button>
</div>
sadsadas
<div style="margin: 0 auto; width: 400px">
<form #formData="ngForm">
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Wpisz emial" ngModel required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Hasło</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Wpisz hasło" name="password" ngModel required>
</div>
<button type="submit" class="btn btn-sm btn-info" (click)="login(formData)" [disabled]="formData.invalid">Zaloguj</button>
</form>
</div>

View File

@ -0,0 +1,30 @@
<div style="margin: 0 auto; width: 80%">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">data zapytania</th>
<th scope="col">lokalizacja</th>
<th scope="col">Data początkowa</th>
<th scope="col">Data końcowa</th>
<th scope="col">Osoba kontaktowa</th>
<th scope="col">Status</th>
<th scope="col">Akcje</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let query of queryList$ | async">
<td>{{query.questiondate | date: 'dd - MM - yyyy' }}</td>
<td>{{ query.location }}</td>
<td>{{query.startdate | date: 'dd - MM - yyyy' }}</td>
<td>{{query.enddate | date: 'dd - MM - yyyy' }}</td>
<td><span *ngIf="query.status === 1"><strong>NOWE</strong></span><span *ngIf="query.status === 2">PRZECZYTANE</span></td>
<td>{{query.contactperson }}</td>
<td>
<button type="button" class="btn btn-success" (click)="showDetails(query)">Szczegóły</button>
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { QueriesListAdminComponent } from './queries-list-admin.component';
describe('QueriesListAdminComponent', () => {
let component: QueriesListAdminComponent;
let fixture: ComponentFixture<QueriesListAdminComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ QueriesListAdminComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(QueriesListAdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,39 @@
import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs';
import {Query} from '../../models/Query';
import {QueryService} from '../../services/query.service';
import {MatDialog} from '@angular/material';
import {CreateQueryComponent} from '../dialogs/create-query/create-query.component';
import {QueryDetailesComponent} from '../dialogs/query-detailes/query-detailes.component';
@Component({
selector: 'app-queries-list-admin',
templateUrl: './queries-list-admin.component.html',
styleUrls: ['./queries-list-admin.component.css']
})
export class QueriesListAdminComponent implements OnInit {
queryList$: Observable<Array<Query>>;
constructor(private queryService: QueryService, private dialog: MatDialog) { }
ngOnInit() {
this.queryService.getQueryList();
this.queryList$ = this.queryService.queryList$;
}
showDetails(query: Query) {
this.openDialog(query);
}
openDialog(query: Query): void {
const dialogRef = this.dialog.open(QueryDetailesComponent, {
// width: '65%',
data: query
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
}

View File

@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Query} from '../models/Query';
import {environment} from '../../environments/environment';
import {BehaviorSubject} from 'rxjs';
import {Term} from '../models/Term';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
@ -12,9 +14,25 @@ const httpOptions = {
})
export class QueryService {
private queryListObs = new BehaviorSubject<Array<Query>>([]);
queryList$ = this.queryListObs.asObservable();
constructor(private httpClient: HttpClient) { }
createQuery(query: Query) {
return this.httpClient.post(environment.API_BACK + 'query', query, httpOptions);
}
getQueryList() {
return this.httpClient.get<Array<Query>>(environment.API_BACK + 'query')
.subscribe(x => {
console.log(x);
this.queryListObs.next(x);
},
err => {
console.log(err);
});
}
}

Binary file not shown.