diff --git a/client/public/stylesheets/style/style.css b/client/public/stylesheets/style/style.css index be988fe1..4915e307 100644 --- a/client/public/stylesheets/style/style.css +++ b/client/public/stylesheets/style/style.css @@ -740,7 +740,16 @@ nav.ol-panel> :last-child { } /****************************************************************************************/ -#import-from-file-dialog td { +#unit-import-export-dialog th { + padding:4px 8px; +} + +#unit-import-export-dialog tr :first-child { + text-align: left; +} + +#unit-import-export-dialog td { + color:white; text-align: center; } diff --git a/client/src/unit/unitdatafile.ts b/client/src/unit/unitdatafile.ts new file mode 100644 index 00000000..b471ce40 --- /dev/null +++ b/client/src/unit/unitdatafile.ts @@ -0,0 +1,3 @@ +export abstract class unitDataFile { + constructor() {} +} \ No newline at end of file diff --git a/client/src/unit/unitdatafileexport.ts b/client/src/unit/unitdatafileexport.ts new file mode 100644 index 00000000..bef50a07 --- /dev/null +++ b/client/src/unit/unitdatafileexport.ts @@ -0,0 +1,73 @@ +import { Dialog } from "../dialog/dialog"; +import { Unit } from "./unit"; +import { unitDataFile } from "./unitdatafile"; + +export class UnitDataFileExport extends unitDataFile { + + #dialog:Dialog; + #element!:HTMLElement; + #categoryCoalitionHeaders!: HTMLElement; + #categoryCoalitionMatrix!: HTMLElement; + + constructor( elementId:string ) { + super(); + this.#dialog = new Dialog(elementId); + this.#element = this.#dialog.getElement(); + this.#categoryCoalitionMatrix = this.#element.querySelector("tbody"); + this.#categoryCoalitionHeaders = this.#element.querySelector("thead"); + } + + /** + * Show the form to start the export journey + */ + showForm(units:Unit[]) { + this.#element.setAttribute( "data-mode", "export" ); + + const data:any = {}; + + const categories:string[] = []; + const coalitions:string[] = []; + + units.filter((unit:Unit) => unit.getControlled() && unit.getAlive()).forEach((unit:Unit) => { + const category = unit.getCategory(); + const coalition = unit.getCoalition(); + + if (!coalitions.includes(coalition)) + coalitions.push(coalition); + + if (!data.hasOwnProperty(category)) { + data[category] = {}; + categories.push(category); + } + + // Cache unit data + if (!data[category].hasOwnProperty(coalition)) + data[category][coalition] = []; + + data[category][coalition].push(unit); + }); + + categories.sort(); + coalitions.sort(); + + let headersHTML:string = ``; + let matrixHTML:string = ``; + + categories.forEach((category:string, index) => { + matrixHTML += `${category}`; + + coalitions.forEach((coalition:string) => { + if (index === 0) + headersHTML += `${coalition}`; + matrixHTML += `${(data[category].hasOwnProperty(coalition)) ? ``: "-"}`; + }); + + matrixHTML += ""; + }); + + this.#categoryCoalitionHeaders.innerHTML = ` ${headersHTML}`; + this.#categoryCoalitionMatrix.innerHTML = matrixHTML; + this.#dialog.show(); + } + +} \ No newline at end of file diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index f50e0d23..80f5b5da 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -15,6 +15,7 @@ import { Popup } from "../popups/popup"; import { HotgroupPanel } from "../panels/hotgrouppanel"; import { Contact, UnitData, UnitSpawnTable } from "../interfaces"; import { Dialog } from "../dialog/dialog"; +import { UnitDataFileExport } from "./unitdatafileexport"; /** The UnitsManager handles the creation, update, and control of units. Data is strictly updated by the server ONLY. This means that any interaction from the user will always and only * result in a command to the server, executed by means of a REST PUT request. Any subsequent change in data will be reflected only when the new data is sent back by the server. This strategy allows @@ -985,6 +986,9 @@ export class UnitsManager { * TODO: Extend to aircraft and helicopters */ exportToFile() { + const fileExport = new UnitDataFileExport("unit-import-export-dialog"); + fileExport.showForm(Object.values(this.#units)); + return; var unitsToExport: { [key: string]: any } = {}; for (let ID in this.#units) { var unit = this.#units[ID]; diff --git a/client/views/other/dialogs.ejs b/client/views/other/dialogs.ejs index 35b56f92..dc7c769d 100644 --- a/client/views/other/dialogs.ejs +++ b/client/views/other/dialogs.ejs @@ -1,6 +1,6 @@ <%- include('dialogs/advancedsettings.ejs') %> <%- include('dialogs/commandmodesettings.ejs') %> <%- include('dialogs/customformation.ejs') %> -<%- include('dialogs/importfromfile.ejs') %> +<%- include('dialogs/importexport.ejs') %> <%- include('dialogs/slowdelete.ejs') %> <%- include('dialogs/splash.ejs') %> \ No newline at end of file diff --git a/client/views/other/dialogs/importexport.ejs b/client/views/other/dialogs/importexport.ejs new file mode 100644 index 00000000..e5e626c2 --- /dev/null +++ b/client/views/other/dialogs/importexport.ejs @@ -0,0 +1,20 @@ +
+
+

Export unit data to file

+
+ +
+

This data will only include Olympus-controlled units.

+ + + + + +
+
+ + +
\ No newline at end of file diff --git a/client/views/other/dialogs/importfromfile.ejs b/client/views/other/dialogs/importfromfile.ejs deleted file mode 100644 index 6074998c..00000000 --- a/client/views/other/dialogs/importfromfile.ejs +++ /dev/null @@ -1,43 +0,0 @@ -
-
-

Import from file

-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 BLUEFORNEUTRALREDFOR
Aircraft
Helicopter  
Ground units
-
- - -
\ No newline at end of file