Skip to content

Commit cf55be5

Browse files
authored
Merge pull request #81 from ITxPT/refactor/fixes
merge refactor/fixes into develop
2 parents c3ee7b3 + a4d5c99 commit cf55be5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+50
-6960
lines changed

app/components/FileUpload.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ const FileUpload = (props: FileUploadProps): JSX.Element => {
8282
event: React.ChangeEvent<HTMLInputElement>
8383
): Promise<void> => {
8484
if (event.target.files == null) {
85-
return // TODO handle
85+
return
8686
}
8787

8888
for (const file of (event.target.files as any)) {
8989
const fileContext = {
9090
name: file.name,
9191
status: 'uploading',
92-
progress: 0
92+
progress: 0,
93+
errorMessage: ''
9394
}
9495

9596
await onUpload(file, (p) => {
@@ -98,7 +99,8 @@ const FileUpload = (props: FileUploadProps): JSX.Element => {
9899
}).then(res => {
99100
fileContext.progress = 100
100101
fileContext.status = 'uploaded'
101-
}).catch(() => {
102+
}).catch((err) => {
103+
fileContext.errorMessage = err.response.statusText
102104
fileContext.status = 'error'
103105
}).finally(() => {
104106
updateFileContext(fileContext)

app/pages/jobs/[id]/files.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const Profiles: NextPage = () => {
119119
disabled={disabled}
120120
onUpload={handleOnUpload}
121121
onChange={handleOnChange}
122-
onError={() => {
123-
return 'File will not be included in the validation'
122+
onError={({ errorMessage }: { errorMessage: string }) => {
123+
return `Error caught uploading file, message: ${errorMessage}`
124124
}}
125125
/>
126126
<Button

app/public/profiles.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"name": "locationsAreReferencingTheSamePoint"
3737
},
3838
{
39-
"name": "passingTimesHaveIncreasingTimes"
39+
"name": "passingTimesIsNotDecreasing"
4040
},
4141
{
4242
"name": "stopPlaceQuayDistanceIsReasonable"
@@ -100,7 +100,7 @@
100100
"name": "locationsAreReferencingTheSamePoint"
101101
},
102102
{
103-
"name": "passingTimesHaveIncreasingTimes"
103+
"name": "passingTimesIsNotDecreasing"
104104
},
105105
{
106106
"name": "stopPlaceQuayDistanceIsReasonable"
@@ -152,7 +152,7 @@
152152
"name": "locationsAreReferencingTheSamePoint"
153153
},
154154
{
155-
"name": "passingTimesHaveIncreasingTimes"
155+
"name": "passingTimesIsNotDecreasing"
156156
},
157157
{
158158
"name": "stopPlaceQuayDistanceIsReasonable"

app/public/scripts.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
]
6363
},
6464
{
65-
"name": "passingTimesHaveIncreasingTimes",
65+
"name": "passingTimesIsNotDecreasing",
6666
"version": "0.0.1",
67-
"description": "Passing times have increasing times",
68-
"longDescription": "Make sure passing times have increasing times and day offsets"
67+
"description": "Passing times don't have decreasing times",
68+
"longDescription": "Make sure passing times don't have decreasing times and day offsets"
6969
},
7070
{
7171
"name": "stopPlaceQuayDistanceIsReasonable",

builtin/everyLineIsReferenced.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ const errors = require("errors");
88
const types = require("types");
99
const xpath = require("xpath");
1010
const linesPath = xpath.join(xpath.path.FRAMES, "ServiceFrame", "lines", "Line");
11-
const journeyLinePath = xpath.join(
12-
xpath.path.FRAMES,
13-
"TimetableFrame",
14-
"vehicleJourneys",
15-
"ServiceJourney",
16-
);
11+
1712
/**
1813
* Make sure every Line is referenced from another element
1914
* @param {types.Context} ctx
@@ -32,10 +27,12 @@ function main(ctx) {
3227
return res;
3328
}
3429

35-
const lineRefsPath = xpath.join(journeyLinePath, `LineRef[@ref='${id}']`);
36-
const refs = ctx.document.find(lineRefsPath).get();
30+
const refExist = ctx.document
31+
.find(".//LineRef")
32+
.getOrElse(() => [])
33+
.find((/** @type {types.Node} n */ n) => n.attr("ref").get() === id);
3734

38-
if (!refs || !refs.length) {
35+
if (!refExist) {
3936
res.push(errors.ConsistencyError(
4037
`Missing reference for Line(@id=${id})`,
4138
{ line: node.line() },

builtin/passingTimesHaveIncreasingTimes.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* @name passingTimesHaveIncreasingTimes
3-
* @overview Makes sure passing times have increasing times and day offsets
2+
* @name passingTimesIsNotDecreasing
3+
* @overview Makes sure passing times don't have decreasing times and day offsets
44
* @author Concrete IT
55
*/
6-
const name = "passingTimesHaveIncreasingTimes";
6+
const name = "passingTimesIsNotDecreasing";
77
const errors = require("errors");
88
const types = require("types");
99
const xpath = require("xpath");
@@ -17,7 +17,7 @@ const departureTimePath = xpath.join("DepartureTime");
1717
const departureOffsetPath = xpath.join("DepartureDayOffset");
1818

1919
/**
20-
* Makes sure passing times have increasing times and day offsets
20+
* Makes sure passing times don't have decreasing times and day offsets
2121
* @param {types.Context} ctx
2222
* @return {errors.ScriptError[]?}
2323
*/
@@ -46,9 +46,9 @@ function worker(ctx) {
4646
const departureDayOffset = node.textAt(departureOffsetPath).get();
4747

4848
if (i !== 0) {
49-
if (prevDepartureTime >= arrivalTime && arrivalDayOffset === prevArrivalDayOffset) {
49+
if (prevDepartureTime > arrivalTime && arrivalDayOffset === prevArrivalDayOffset) {
5050
res.push(errors.ConsistencyError(
51-
`Expected passing time to increase in ServiceJourney(@id=${id}), TimetabledPassingTime(@id=${tid})`,
51+
`Expected passing time to not decrease in ServiceJourney(@id=${id}), TimetabledPassingTime(@id=${tid})`,
5252
{ line: node.line() },
5353
));
5454
}

cmd/mqtt.go

-79
This file was deleted.

cmd/server.go

-36
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import (
88
"fmt"
99
"log"
1010
"net/http"
11-
"net/url"
1211
"sort"
1312
"time"
1413

1514
"github.com/caarlos0/env/v6"
16-
"github.com/concreteit/greenlight/internal"
17-
"github.com/gorilla/websocket"
18-
"github.com/koding/websocketproxy"
1915
"github.com/labstack/echo/v4"
2016
"github.com/labstack/echo/v4/middleware"
2117
"github.com/spf13/cobra"
@@ -57,10 +53,8 @@ type WebConfig struct {
5753

5854
func init() {
5955
serverCmd.Flags().StringP("port", "p", "8080", "Which port to listen http server on")
60-
serverCmd.Flags().StringP("mqtt-port", "", "1883", "Which port to listen mqtt server on")
6156

6257
viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
63-
viper.BindPFlag("mqtt-port", serverCmd.Flags().Lookup("mqtt-port"))
6458

6559
rootCmd.AddCommand(serverCmd)
6660

@@ -75,13 +69,6 @@ func startServer(cmd *cobra.Command, args []string) {
7569
port = "8080"
7670
}
7771

78-
broker, err := NewMQTTBroker(DefaultBrokerConfig())
79-
if err != nil {
80-
log.Fatalln(err)
81-
}
82-
83-
broker.Start()
84-
8572
fs := http.FileServer(StaticDir{http.Dir("app/out")})
8673
e := echo.New()
8774
e.HTTPErrorHandler = func(err error, c echo.Context) {
@@ -214,15 +201,6 @@ func startServer(cmd *cobra.Command, args []string) {
214201
return err
215202
}
216203

217-
v.Subscribe(func(event internal.Event) {
218-
switch event.Type {
219-
case internal.EventTypeValidateDocumentStart, internal.EventTypeValidateDocumentStop:
220-
broker.PublishMessage(fmt.Sprintf("sessions/%s/documents/%s", session.ID, event.Data["document"]), event)
221-
case internal.EventTypeScriptStart, internal.EventTypeScriptStop:
222-
broker.PublishMessage(fmt.Sprintf("sessions/%s/documents/%s/scripts/%s", session.ID, event.Data["document"], event.Data["script"]), event)
223-
}
224-
})
225-
226204
res, err := v.Validate(context.Background())
227205
if err != nil {
228206
session.Stopped = time.Now()
@@ -331,20 +309,6 @@ func startServer(cmd *cobra.Command, args []string) {
331309
return c.String(http.StatusBadRequest, "unsupported file format")
332310
})
333311

334-
u, err := url.Parse("ws://localhost:1888/ws")
335-
if err != nil {
336-
log.Fatalln(err)
337-
}
338-
339-
wsProxy := websocketproxy.NewProxy(u)
340-
wsProxy.Upgrader = &websocket.Upgrader{}
341-
wsProxy.Upgrader.CheckOrigin = func(r *http.Request) bool { return true }
342-
343-
e.GET("/ws", func(c echo.Context) error {
344-
wsProxy.ServeHTTP(c.Response(), c.Request())
345-
return nil
346-
})
347-
348312
e.Any("*", func(c echo.Context) error {
349313
fs.ServeHTTP(c.Response(), c.Request())
350314
return nil

fork/hmq/.github/workflows/go.yml

-23
This file was deleted.

fork/hmq/.gitignore

-9
This file was deleted.

fork/hmq/Dockerfile

-12
This file was deleted.

0 commit comments

Comments
 (0)