Skip to content

Commit

Permalink
sub-packages, quotation marking and environment variables implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxcode committed Sep 15, 2022
1 parent 4ca96eb commit 1114bd8
Show file tree
Hide file tree
Showing 102 changed files with 1,229 additions and 944 deletions.
83 changes: 0 additions & 83 deletions assets/fonts.css

This file was deleted.

3 changes: 3 additions & 0 deletions build-release.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
cd internal\config
go generate
cd ..\..
go generate
go build -ldflags "-H=windowsgui -s -w" -trimpath
3 changes: 3 additions & 0 deletions build-release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
cd internal/config
go generate
cd ../..
go generate
go build -ldflags "-s -w" -trimpath
#chmod +x ./edm
Expand Down
7 changes: 5 additions & 2 deletions companies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"database/sql"
"edm/pkg/accs"
"encoding/json"
"log"
"net/http"
Expand All @@ -13,6 +14,7 @@ import (
// CompaniesPage is passed into template
type CompaniesPage struct {
AppTitle string
AppVersion string
PageTitle string
LoggedinID int
LoggedinAdmin bool
Expand All @@ -39,6 +41,7 @@ func (bs *BaseStruct) companiesHandler(w http.ResponseWriter, r *http.Request) {

var Page = CompaniesPage{
AppTitle: bs.text.AppTitle,
AppVersion: AppVersion,
PageTitle: bs.text.CompaniesPageTitle,
LoggedinID: id,
}
Expand Down Expand Up @@ -137,7 +140,7 @@ ORDER BY c.ShortName ASC, c.FullName ASC, c.ForeignName ASC`)
}()

if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
//http.Error(w, err.Error(), http.StatusInternalServerError) //Commented to not displayng error details to end user
return
Expand All @@ -155,7 +158,7 @@ ORDER BY c.ShortName ASC, c.FullName ASC, c.ForeignName ASC`)
// HTML output
err = bs.templates.ExecuteTemplate(w, "companies.tmpl", Page)
if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
//http.Error(w, err.Error(), http.StatusInternalServerError) //Commented to not displayng error details to end user
return
Expand Down
21 changes: 12 additions & 9 deletions company.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"database/sql"
"edm/pkg/accs"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -40,7 +41,7 @@ func unmarshalNonEmptyCompanyContacts(c string) (res CompanyContacts) {
if c != "" {
err := json.Unmarshal([]byte(c), &res)
if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
}
}
return res
Expand Down Expand Up @@ -255,6 +256,7 @@ func (u Unit) GiveHeadNameJob() (head string) {
// CompanyPage is passed into template
type CompanyPage struct {
AppTitle string
AppVersion string
PageTitle string
LoggedinID int
UserConfig UserConfig
Expand Down Expand Up @@ -282,6 +284,7 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {

var Page = CompanyPage{
AppTitle: bs.text.AppTitle,
AppVersion: AppVersion,
LoggedinID: id,
Editable: false,
New: false,
Expand All @@ -293,7 +296,7 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
Page.Editable = true
}

TextID := getTextIDfromURL(r.URL.Path)
TextID := accs.GetTextIDfromURL(r.URL.Path)
IntID, _ := strconv.Atoi(TextID)

var created int
Expand All @@ -302,7 +305,7 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
// Create or update code ==========================================================================
if r.Method == "POST" && (r.FormValue("createButton") != "" || r.FormValue("updateButton") != "") {
if Page.Editable == false {
throwAccessDenied(w, "writing company", Page.LoggedinID, IntID)
accs.ThrowAccessDenied(w, "writing company", Page.LoggedinID, IntID)
return
}
c := Company{
Expand Down Expand Up @@ -358,7 +361,7 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
// Create or update Units =====================================================================
if r.Method == "POST" && (r.FormValue("createUnit") != "" || r.FormValue("updateUnit") != "") {
if Page.Editable == false {
throwAccessDenied(w, "writing unit", Page.LoggedinID, IntID)
accs.ThrowAccessDenied(w, "writing unit", Page.LoggedinID, IntID)
return
}
UnitIntID, _ := strconv.Atoi(r.FormValue("unitID"))
Expand Down Expand Up @@ -389,7 +392,7 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
// Delete Unit ================+==========================
if r.Method == "POST" && r.FormValue("deleteUnit") != "" {
if Page.Editable == false {
throwAccessDenied(w, "writing unit", Page.LoggedinID, IntID)
accs.ThrowAccessDenied(w, "writing unit", Page.LoggedinID, IntID)
return
}
UnitIntID, _ := strconv.Atoi(r.FormValue("unitID"))
Expand All @@ -414,13 +417,13 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
Page.Company.ID = IntID
err = Page.Company.load(bs.db, bs.dbt)
if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.NotFound(w, r)
return
}
Page.Units, err = Page.Company.loadUnits(bs.db, bs.dbt)
if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.NotFound(w, r)
return
}
Expand Down Expand Up @@ -448,8 +451,8 @@ func (bs *BaseStruct) companyHandler(w http.ResponseWriter, r *http.Request) {
// HTML output
err = bs.templates.ExecuteTemplate(w, "company.tmpl", Page)
if err != nil {
log.Println(currentFunction()+":", err)
throwServerError(w, "executing company template", Page.LoggedinID, Page.Company.ID)
log.Println(accs.CurrentFunction()+":", err)
accs.ThrowServerError(w, "executing company template", Page.LoggedinID, Page.Company.ID)
return
}

Expand Down
14 changes: 0 additions & 14 deletions edm_test.go → date_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
package main

import (
"strings"
"testing"
)

func TestReadiniForComments(t *testing.T) {
testmap, err := readini("./testfiles/testini.cfg")
if err != nil {
t.Errorf("Expected map of settings, received:%v", err)
}
for k, v := range testmap {
t.Log("pair:" + k + ":" + v)
if strings.Contains(k, "#commented") {
t.Errorf("Expected omit comments, received:%s:%s", k, v)
}
}
}

func TestDateToInt64(t *testing.T) {
var d, rev Date
var res int64
Expand Down
7 changes: 5 additions & 2 deletions docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"database/sql"
"edm/pkg/accs"
"encoding/json"
"log"
"net/http"
Expand All @@ -14,6 +15,7 @@ import (
// DocsPage is passed into template
type DocsPage struct {
AppTitle string
AppVersion string
PageTitle string
LoggedinID int
LoggedinAdmin bool
Expand Down Expand Up @@ -50,6 +52,7 @@ func (bs *BaseStruct) docsHandler(w http.ResponseWriter, r *http.Request) {

var Page = DocsPage{
AppTitle: bs.text.AppTitle,
AppVersion: AppVersion,
PageTitle: bs.text.DocsPageTitle,
Categories: bs.text.Categories,
DocTypes: bs.text.DocTypes,
Expand Down Expand Up @@ -264,7 +267,7 @@ func (bs *BaseStruct) docsHandler(w http.ResponseWriter, r *http.Request) {
}()

if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
//http.Error(w, err.Error(), http.StatusInternalServerError) //Commented to not displayng error details to end user
return
Expand All @@ -286,7 +289,7 @@ func (bs *BaseStruct) docsHandler(w http.ResponseWriter, r *http.Request) {
// HTML output
err = bs.templates.ExecuteTemplate(w, "docs.tmpl", Page)
if err != nil {
log.Println(currentFunction()+":", err)
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
//http.Error(w, err.Error(), http.StatusInternalServerError) //Commented to not displayng error details to end user
return
Expand Down
Loading

0 comments on commit 1114bd8

Please sign in to comment.