From 969e6b1b87475f7b3511401bfec0464565260d17 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 28 Nov 2021 16:50:58 +1000 Subject: [PATCH] Converted from MySQL to PgSQL --- AjaxController.fs | 1 + Browser.module.fs | 23 +------------ Database.module.fs | 19 ++++++----- DredgePos.fsproj | 3 +- Floorplan.module.fs | 32 +++++++------------ GenericEntities.module.fs | 11 ++----- Program.fs | 1 - Types.fs | 1 + wwwroot/scripts/ts/dredgepos.floorplan.ts | 14 +++++--- wwwroot/scripts/ts/dredgepos.orderScreen.ts | 3 +- wwwroot/scripts/ts/types.ts | 5 +-- wwwroot/styles/sass/dredgepos.floorplan.sass | 1 + .../styles/sass/dredgepos.orderScreen.sass | 3 +- 13 files changed, 44 insertions(+), 73 deletions(-) diff --git a/AjaxController.fs b/AjaxController.fs index 9ec7c9c..9c7d1ca 100644 --- a/AjaxController.fs +++ b/AjaxController.fs @@ -108,6 +108,7 @@ let AddDecoration (data: floorplan_decoration) = decoration_pos_x = data.decoration_pos_x decoration_pos_y = data.decoration_pos_y decoration_room = data.decoration_room + venue_id = data.venue_id } Entity.addToDatabase decoration diff --git a/Browser.module.fs b/Browser.module.fs index 3d928e3..4f8343e 100644 --- a/Browser.module.fs +++ b/Browser.module.fs @@ -26,25 +26,4 @@ let setCookie name value (expiry: DateTimeOffset) (context: HttpContext) = context.Response.Cookies.Append(name, value, options); let redirect url (context: HttpContext) = - context.Response.Redirect url - -let addRoute path controller (endpoints: IEndpointRouteBuilder) = - endpoints.MapGet(path, fun context -> - context.Response.WriteAsync(controller())) |> ignore - endpoints - -let addRouteWithParameter path controller param1 (endpoints: IEndpointRouteBuilder) = - endpoints.MapGet(path, fun context -> - let param1Name, param1Type = param1 - let parameter1 = context.Request.RouteValues.[param1Name] |> string |> param1Type - context.Response.WriteAsync(controller parameter1)) |> ignore - endpoints - -let addRouteWithParameters path controller param1 param2 (endpoints: IEndpointRouteBuilder) = - endpoints.MapGet(path, fun context -> - let param1Name, param1Type = param1 - let param2Name, param2Type = param2 - let parameter1 = context.Request.RouteValues.[param1Name] |> string |> param1Type - let parameter2 = context.Request.RouteValues.[param2Name] |> string |> param2Type - context.Response.WriteAsync(controller parameter1 parameter2)) |> ignore - endpoints \ No newline at end of file + context.Response.Redirect url \ No newline at end of file diff --git a/Database.module.fs b/Database.module.fs index a8b1f74..68ba70e 100644 --- a/Database.module.fs +++ b/Database.module.fs @@ -2,12 +2,14 @@ open Dapper open Dapper.FSharp -open Dapper.FSharp.MySQL -open MySql.Data.MySqlClient +open Dapper.FSharp.PostgreSQL + + open DredgeFramework -let connString = "server=localhost;uid=root;pwd=;database=dredgepos;table cache = false" -let connection = new MySqlConnection(connString) +let connString = "Server=localhost;Port=5432;User Id=postgres;Password=root;Database=dredgepos;Include Error Detail=true" +//let connString = "server=localhost;uid=root;pwd=;database=dredgepos;table cache = false" +let connection = new Npgsql.NpgsqlConnection(connString) let Select<'a> asyncQuery = asyncQuery @@ -28,18 +30,15 @@ let Insert<'a> asyncQuery = let InsertOutput<'a> asyncQuery = asyncQuery - |> connection.InsertAsync<'a> + |> connection.InsertOutputAsync<'a, 'a> |> RunSynchronously - |> ignore - - let table = asyncQuery.Table - connection.Query<'a>($"""Select * From {table} Where id = (select last_insert_id())""") |> EnumerableToArray let Update<'a> asyncQuery = asyncQuery - |> connection.UpdateAsync<'a> + |> connection.UpdateOutputAsync<'a, 'a> |> RunSynchronously + |> EnumerableToArray let Delete<'a> asyncQuery = asyncQuery diff --git a/DredgePos.fsproj b/DredgePos.fsproj index baec57e..65ea817 100644 --- a/DredgePos.fsproj +++ b/DredgePos.fsproj @@ -40,8 +40,9 @@ - + + diff --git a/Floorplan.module.fs b/Floorplan.module.fs index d7a0a37..4eea807 100644 --- a/Floorplan.module.fs +++ b/Floorplan.module.fs @@ -1,6 +1,7 @@ module Floorplan open DredgePos +open Org.BouncyCastle.Asn1.X509 open Reservations open System @@ -115,28 +116,12 @@ let getRoom (roomId: int) = where (eq "id" roomId) } |> db.Select |> first -let updateFloorplanTable (tableNumber:int) (column: string) value = - //TODO: Make update query venue specific - let sql = "Update floorplan_tables Set @column = @value Where table_number = @tableNumber" - let parameters = [("column", box column); ("value", box value); ("tableNumber", box tableNumber)] - db.connection.Execute(sql, parameters) |> ignore - - getTable tableNumber - -let updateTableShape (floorplanTable: floorplan_table) = - update { - table "floorplan_tables" - set floorplanTable - where (eq "table_number" floorplanTable.table_number + eq "venue_id" (getCurrentVenue())) - } |> db.Update - - let updateTablePosition (floorplanTable: floorplan_table) = Entity.updateInDatabase floorplanTable let createEmptyReservation (reservation: reservation) = update { table "floorplan_tables" - set {| status = 2 |} + set {| status = 2 |}Target where(eq "id" reservation.reservation_table_id) } |> db.Update |> ignore @@ -306,11 +291,16 @@ let makeRoomButton (room: floorplan_room) = let getReservationList (tableList: floorplan_table[]) = let tableIds = tableList - |> Array.map(fun table -> table.id) - |> JoinArray "," + |> Array.map(fun table -> box table.id) + |> List.ofArray - db.connection.Query($"""Select * From reservations Where reservation_table_id In ({tableIds})""") - |> EnumerableToArray + if tableIds.Length > 0 then + select { + table "reservations" + where (isIn "reservation_table_id" tableIds) + } + |> db.Select + else [||] let newReservation name time covers = let reservation = { diff --git a/GenericEntities.module.fs b/GenericEntities.module.fs index fe8b8d5..154ba0c 100644 --- a/GenericEntities.module.fs +++ b/GenericEntities.module.fs @@ -1,21 +1,18 @@ module Entity -open DredgePos -open Types open Dapper.FSharp open DredgeFramework open Pluralize.NET.Core -open FSharp.Reflection + let getDatabaseTable<'x> = let typeName = typeof<'x>.Name Pluralizer().Pluralize typeName - - let addToDatabase (record: 'x)= let tableName = getDatabaseTable<'x> insert { table tableName value record + excludeColumn "id" } |> db.InsertOutput |> first @@ -24,14 +21,12 @@ let addToDatabase (record: 'x)= let inline updateInDatabase (record: ^x) = let tableName = getDatabaseTable<'x> let id = ((^x) : (member id : int) (record)) - (* Run an update query *) update { table tableName set record where (eq "id" id) } - |> db.Update |> ignore - record + |> db.Update let getAll<'x> = let typeName = typeof<'x>.Name diff --git a/Program.fs b/Program.fs index 1f0ce9f..8099f95 100644 --- a/Program.fs +++ b/Program.fs @@ -36,7 +36,6 @@ module Program = getf "/getKeyboardLayout/%s" AjaxController.getKeyboardLayout get "/languageVars" (json <| AjaxController.getLanguageVars) get "/getOpenTables" (json <| Floorplan.getActiveTables (DredgeFramework.getCurrentVenue())) - getf "/getActiveTables/%i" AjaxController.getActiveTables getf "/getFloorplanData/%i" AjaxController.getFloorplanData getf "/tableIsOpen/%i" (fun tableNumber -> json <| Floorplan.tableNumberIsOpen tableNumber) getf "/transferTable/%i/%i" AjaxController.transferTable diff --git a/Types.fs b/Types.fs index 584c999..3c8445e 100644 --- a/Types.fs +++ b/Types.fs @@ -54,6 +54,7 @@ type floorplan_decoration = { decoration_width: int decoration_height: int decoration_image: string + venue_id: int } [] diff --git a/wwwroot/scripts/ts/dredgepos.floorplan.ts b/wwwroot/scripts/ts/dredgepos.floorplan.ts index 954679b..c5058a6 100644 --- a/wwwroot/scripts/ts/dredgepos.floorplan.ts +++ b/wwwroot/scripts/ts/dredgepos.floorplan.ts @@ -113,7 +113,7 @@ const loadRoom = (roomToLoad: room) => { setupKonva() $('.roomButton').removeClass('active') - let button = $(`.roomButton[data-value=${roomToLoad.id}]`) + let button = $(`.roomButton[data-value=${roomToLoad?.id}]`) button.addClass('active') const tablesInRoom = Floorplan.tables.filter(table => table.room_id == roomToLoad.id) @@ -391,7 +391,7 @@ const tableUnreserved = (table: table) => { const getSelectedTableData = () => getTableDataFromTableNumber(Floorplan.selectedTableNumber) const deselectTables = () => { - Floorplan.stage.find('Rect, Ellipse').forEach( (shape: Konva.Shape, index) => { + Floorplan.stage.find('Rect, Ellipse').forEach( (shape: Konva.Shape) => { shape.stroke('black') }); @@ -536,6 +536,7 @@ const decorationTransformed = (event: Konva.KonvaEventObject|Konva.K decoration_width: Math.round((decorationShape.scaleX() * decorationShape.width()) / Floorplan.visualScale), decoration_height: Math.round((decorationShape.scaleY() * decorationShape.height()) / Floorplan.visualScale), decoration_image: oldDecorationData.decoration_image, + venue_id: oldDecorationData.venue_id, } saveDecoration(newDecoration) @@ -569,7 +570,8 @@ const addDecoration = (e: Event) => { decoration_rotation: 0, decoration_width: 200, decoration_height: 200, - decoration_image: button.data('image') + decoration_image: button.data('image'), + venue_id: Floorplan.currentRoom.venue_id } ajax('/ajax/addDecoration', newDecoration, 'post', decorationAdded, null, null) @@ -599,8 +601,10 @@ const setRoomBackground = (roomToLoad: room) => { const width = Floorplan.floorplanDiv.width() const height = Floorplan.floorplanDiv.height() - Floorplan.floorplanDiv.css("background-image", `url(images/rooms/${roomToLoad.background_image})`) - Floorplan.floorplanDiv.css("background-size", `${width}px ${height}px`) + if(roomToLoad.background_image) { + Floorplan.floorplanDiv.css("background-image", `url(images/rooms/${roomToLoad?.background_image})`) + Floorplan.floorplanDiv.css("background-size", `${width}px ${height}px`) + } } const setupKonva = () => { diff --git a/wwwroot/scripts/ts/dredgepos.orderScreen.ts b/wwwroot/scripts/ts/dredgepos.orderScreen.ts index c9ac793..b9f69c6 100644 --- a/wwwroot/scripts/ts/dredgepos.orderScreen.ts +++ b/wwwroot/scripts/ts/dredgepos.orderScreen.ts @@ -13,7 +13,6 @@ const loadPageGroup = (e: Event) => { let pageGroupId = button.data('page-group-id') $('.pageGroup').hide() let activeGrid = $(`.pageGroup[data-page-group-id=${pageGroupId}]`) - let navButtons = $('.pageNavigation') activeGrid.find('.gridPage').length > 1 @@ -30,7 +29,7 @@ const setupOrderScreen = (data: OrderScreen) => { doc.on('click', '.prevButton', goToPrevPage) doc.on('click', '.loadPageGroup', loadPageGroup) - let initialPage = $('.loadPageGroup').first().trigger('click') + $('.loadPageGroup').first().trigger('click') } /** diff --git a/wwwroot/scripts/ts/types.ts b/wwwroot/scripts/ts/types.ts index 97adf82..3679a00 100644 --- a/wwwroot/scripts/ts/types.ts +++ b/wwwroot/scripts/ts/types.ts @@ -39,6 +39,7 @@ interface decoration { decoration_width: number decoration_height: number decoration_image: string + venue_id: number } interface room { @@ -65,6 +66,6 @@ interface keyboard { currentLayout: string } -interface order_screen_page_group {id: number; venue_id: number; label: string} interface order_screen_page{id: number; order_screen_page_group_id: number; grid_id: number} -interface grid {id: number; grid_name: string; grid_rows: number; grid_cols: number; grid_data: string} \ No newline at end of file +interface grid {id: number; grid_name: string; grid_rows: number; grid_cols: number; grid_data: string} + diff --git a/wwwroot/styles/sass/dredgepos.floorplan.sass b/wwwroot/styles/sass/dredgepos.floorplan.sass index 9ef5245..ed76695 100644 --- a/wwwroot/styles/sass/dredgepos.floorplan.sass +++ b/wwwroot/styles/sass/dredgepos.floorplan.sass @@ -62,6 +62,7 @@ #floorplanCanvas aspect-ratio: 1/1 background-repeat: no-repeat + background: var(--global-secondary-bgcolor) > *:not(#floorplanCanvas) @include flex-column-item diff --git a/wwwroot/styles/sass/dredgepos.orderScreen.sass b/wwwroot/styles/sass/dredgepos.orderScreen.sass index 535d258..2777b1f 100644 --- a/wwwroot/styles/sass/dredgepos.orderScreen.sass +++ b/wwwroot/styles/sass/dredgepos.orderScreen.sass @@ -79,7 +79,7 @@ @include flex @include flex-column-item flex-basis: 10% - background-color: magenta + background-color: var(--global-secondary-bgcolor) flex-grow: 0 flex-shrink: 0 @@ -192,6 +192,7 @@ .pageNavigation @include flex @include flex-column-item + display: none flex-basis: 15% > *