Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move server to fastapi #43

Closed
wants to merge 244 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
244 commits
Select commit Hold shift + click to select a range
87d9609
Initial commit: Moved all related backend server code to FastAPI.
CopyDemon Nov 2, 2023
954a765
update react build folder to idaes_ui.fv/
CopyDemon Nov 2, 2023
365e437
import Flowsheetapp, use new Fastapi app replace the old http server …
CopyDemon Nov 2, 2023
4657e2c
move build to idaes_fv.reactBuild run react build
CopyDemon Nov 2, 2023
1e0efef
create root server static react app, reorder define root and mount st…
CopyDemon Nov 6, 2023
5441f20
open new web service with fastapi pass flowsheet and name as params
CopyDemon Nov 6, 2023
262b820
update route order put fs to front
CopyDemon Nov 6, 2023
814ee9a
update route order, should define api route first then mount static f…
CopyDemon Nov 6, 2023
cdba1f0
update api link from example: /fs/ into /api/get_fs/ etc. make it mor…
CopyDemon Nov 6, 2023
1e2028a
enable CORS for dev env port 5173
CopyDemon Nov 6, 2023
693f2bd
update when dev server port point to 8000 match fastapi port
CopyDemon Nov 6, 2023
ac4c9ac
update server_port to 8000 match to fastapi port
CopyDemon Nov 6, 2023
a4751d8
update get and put fs api links
CopyDemon Nov 6, 2023
4ff966e
run build static and test
CopyDemon Nov 6, 2023
ef9768c
add 8000 as a CORS, update api end point remove / from end of url
CopyDemon Nov 6, 2023
7e45c78
CORS won't use * but use origins[]
CopyDemon Nov 6, 2023
b198c0a
react use port 8000 as defult port
CopyDemon Nov 6, 2023
8f06695
update getTimeInterval fn update api url update if res.val set it as …
CopyDemon Nov 6, 2023
ea85935
remove import model_server.py'
CopyDemon Nov 6, 2023
709f7cd
add 127.0.0.1:8000 as one of the origins
CopyDemon Nov 6, 2023
a22a2bd
react run build
CopyDemon Nov 6, 2023
4c4f937
fix event loop error rewrite .run() by using asyncio and also check i…
CopyDemon Nov 6, 2023
41531f5
format with black
CopyDemon Nov 7, 2023
ce34322
turn off old http server, will remove this file later
CopyDemon Nov 7, 2023
2145ec4
use ms as time as default
CopyDemon Nov 7, 2023
ae9c8c3
define basic doc structure of fastapi
CopyDemon Nov 7, 2023
2babda5
move cors to another file
CopyDemon Nov 7, 2023
a57bd21
import core and call function
CopyDemon Nov 7, 2023
0027453
only run on local so enable all port can pass CORS
CopyDemon Nov 11, 2023
a24ccf7
try fix error 'flowsheet.py:556: FutureWarning: DataFrame.applymap ha…
CopyDemon Nov 11, 2023
f11b334
format
CopyDemon Nov 11, 2023
34d57a7
add nest_asyncio as part of package for prevent event loop already ru…
CopyDemon Nov 11, 2023
39edd68
move uvicorn run fastapp app to its own class
CopyDemon Nov 11, 2023
cd9effd
init fastapi_functions as part of package
CopyDemon Nov 11, 2023
7b2848c
move uvicorn serve fastapi to its own file
CopyDemon Nov 11, 2023
5917d17
add comment
CopyDemon Nov 11, 2023
1919fc4
update fsvis use fastapi app, comment old web_server fns re do them l…
CopyDemon Nov 11, 2023
68e2bbc
remove arg from serve() fix error
CopyDemon Nov 12, 2023
964d9f9
add modular router
CopyDemon Nov 14, 2023
33d8c3c
move get flowsheet to its own route
CopyDemon Nov 14, 2023
0d07c70
move static endpoint to its own file
CopyDemon Nov 14, 2023
25eb401
remove while uvicorn directly stop the server with ctr + c
CopyDemon Nov 14, 2023
73a5b3b
add fn check port is available if not update port
CopyDemon Nov 14, 2023
d1b0d00
initial put api endpoint
CopyDemon Nov 14, 2023
f8305d3
initial put api endpoint
CopyDemon Nov 14, 2023
7736b08
remove sensitive info
CopyDemon Nov 14, 2023
a30e30c
just format
CopyDemon Nov 15, 2023
5ab5a4b
remove token
CopyDemon Nov 15, 2023
2cd16b7
work save add running port storage
CopyDemon Nov 15, 2023
1fc0305
work save put fs end point
CopyDemon Nov 15, 2023
4a57eb2
version should not be 1.0.0 should be 0.1.0, update git ui all point …
CopyDemon Nov 15, 2023
273d465
enable baisc put req for put fs
CopyDemon Nov 15, 2023
a17a52e
move save flowsheet(put fs) to its own file
CopyDemon Nov 15, 2023
cc3707b
move get diagnostic to its own class
CopyDemon Nov 15, 2023
e237d99
update the port for dev env
CopyDemon Nov 15, 2023
ef0bc4b
add get app setting route move it to own file and remove from app.py
CopyDemon Nov 15, 2023
466eda7
add get app setting route
CopyDemon Nov 15, 2023
85f463a
remove initial setting this will initial from app setting route
CopyDemon Nov 15, 2023
6fe117c
add param save_time_interval if user want to define their own time
CopyDemon Nov 15, 2023
a128246
reorder code order put initial related flowsheet to front
CopyDemon Nov 15, 2023
9f11168
remove get flowsheet it's already in it's own route file
CopyDemon Nov 15, 2023
219848c
add save dir and define self.save dir
CopyDemon Nov 15, 2023
bb63738
format
CopyDemon Nov 15, 2023
9cc24b1
add flowsheet store location save_dir
CopyDemon Nov 15, 2023
66e9216
add save_dir param
CopyDemon Nov 15, 2023
f8b57f1
add save_dir param
CopyDemon Nov 15, 2023
73c4410
move initial self... params into its own file or it's too long to rea…
CopyDemon Nov 16, 2023
dcc7fa8
remove defined path, that path move to api route serve static files
CopyDemon Nov 16, 2023
dc08859
update app save url
CopyDemon Nov 16, 2023
4486765
work save check user already has saved flowsheet
CopyDemon Nov 16, 2023
e789594
work save, return fs only, now you can ignore this
CopyDemon Nov 16, 2023
52be925
update param in route pass from fastapi app class
CopyDemon Nov 16, 2023
fb2e804
add flowsheet_manager class to manage get and set new flowsheet to bo…
CopyDemon Nov 16, 2023
a8b7221
update get request return flowsheet from flowsheet_manager
CopyDemon Nov 16, 2023
8cf628a
updat put endpoint now use it to receive user req, use flowsheet mana…
CopyDemon Nov 16, 2023
6116796
run build react
CopyDemon Nov 16, 2023
c0a123b
react save modle param update from fs to jjs_fs
CopyDemon Nov 16, 2023
6eaec6f
update dev port to 49999
CopyDemon Nov 16, 2023
27d1a5f
rename get update and original flowsheet name frontend use jjs format…
CopyDemon Nov 16, 2023
cff50bd
rename get update and original flowsheet name frontend use jjs format…
CopyDemon Nov 16, 2023
9de51e9
call flowsheet manager as a middleware, to manage state of flowsheet
CopyDemon Nov 16, 2023
d8e1e3b
work save health check
CopyDemon Nov 20, 2023
255fce2
add health check route
CopyDemon Nov 20, 2023
b4dc72f
add update uvicorn run
CopyDemon Nov 20, 2023
38ee2ad
run build react again
CopyDemon Nov 21, 2023
bdc4a44
add ignore runnning_server.pickle, this one is use to track running s…
CopyDemon Nov 22, 2023
01bdf04
request package for python send request to fastapi
CopyDemon Nov 22, 2023
8505ee9
fastapi get take query param to query flowsheet name
CopyDemon Nov 22, 2023
f459ff9
loading is not correct just update flowsheet not found if not found f…
CopyDemon Nov 22, 2023
bb8a18f
uvicorn class take one more param flowsheet name
CopyDemon Nov 22, 2023
b44b573
work save webserver start with ServerManager class
CopyDemon Nov 22, 2023
2cf8416
update update original flowsheet fn, add get flowsheet name fn
CopyDemon Nov 22, 2023
965c607
work save, add server manager, use to control logic if need to start …
CopyDemon Nov 22, 2023
adb86d5
work save update uvicorn script with async run, won't block the jupyt…
CopyDemon Nov 22, 2023
cceb5c9
work save, simplize get_fs endpoint, by use query string to return fl…
CopyDemon Nov 22, 2023
af24919
work save testing health check now return turn, will update later
CopyDemon Nov 22, 2023
7be79fc
work save update put_fs endpoint base on put what type of flowsheet t…
CopyDemon Nov 22, 2023
05b9b1a
update flowsheet manager required params
CopyDemon Nov 22, 2023
3ed2f14
react run build
CopyDemon Nov 22, 2023
86b254a
read app setting
CopyDemon Nov 28, 2023
78c02b8
Merge branch 'IDAES:main' into main
CopyDemon Nov 28, 2023
1c99f2e
update vite build path
CopyDemon Nov 28, 2023
f872b14
remove old ui static files
CopyDemon Nov 28, 2023
08d731b
react run build to idaes_ui.fv.static fileder
CopyDemon Nov 28, 2023
14ed9b7
update simple http server serve react build file from static folder
CopyDemon Nov 28, 2023
9094bc9
remove shared_variable.json file path build, this path is not valid a…
CopyDemon Nov 28, 2023
9c95bf5
remove worlflow test extract server port, the dev test port is fix to…
CopyDemon Nov 28, 2023
02ab6e2
merge main resolve conflict keep main's change but comment out model …
CopyDemon Nov 28, 2023
140f3b5
react run build
CopyDemon Nov 28, 2023
6ffb395
update serve static file path to static/
CopyDemon Nov 28, 2023
532c7f5
delete reactBuild folder, now build files are in idaes_ui.fv.static
CopyDemon Nov 28, 2023
971baa6
work save : try to find a way to continue monitor user change model
CopyDemon Nov 28, 2023
948ae07
work save : try to find a way to continue monitor user change model
CopyDemon Nov 28, 2023
125e71f
update the way to read param from merge_flowsheets fn
CopyDemon Dec 6, 2023
808c684
update fetch get to decide where to pick the data
CopyDemon Dec 6, 2023
8d8c772
work save: remove useless import, and remove flowsheet_monitor while …
CopyDemon Dec 6, 2023
c87e352
fix 2 errors. 1. when user execute on notebook with new unit the ui n…
CopyDemon Dec 6, 2023
614d8a1
1.update how app get the available port. 2. remove while loop check i…
CopyDemon Dec 6, 2023
396ba5b
update port-> read port from parent class, remove port check move to …
CopyDemon Dec 6, 2023
2e8a837
update put request, return message and updated fs
CopyDemon Dec 6, 2023
38b0dea
update cypress base url
CopyDemon Dec 11, 2023
ffd817d
Merge branch 'IDAES:main' into main
CopyDemon Dec 11, 2023
d27959e
update *.pickle as a ignore file
CopyDemon Dec 11, 2023
bbfe105
Merge branch 'main' into move_server_to_fastapi
CopyDemon Dec 11, 2023
5e72759
all UI related test move to cypress to simplify the test
CopyDemon Dec 11, 2023
f9a5aba
server is move to fastAPI
CopyDemon Dec 11, 2023
c2b4b20
mark to do now use in ui script demo_flowsheet todo is to use idaes-p…
CopyDemon Dec 11, 2023
b3892d0
update pytest path from idaes_ui.fv to ./idaes_ui/fv or show error mi…
CopyDemon Dec 30, 2023
06cd1fe
update savetime interval to 5 not 5000ms later will process this ms t…
CopyDemon Dec 30, 2023
9e2d20f
work save 1. update savetime interval to 5 not 5000ms later will proc…
CopyDemon Dec 30, 2023
8f43f69
add save time interval related param and fn
CopyDemon Dec 30, 2023
d668825
update savetime interval to 5 not 5000ms later will process this ms t…
CopyDemon Dec 30, 2023
14ae61b
add save_time_interval, add type for params
CopyDemon Dec 30, 2023
bc414fd
add get_save_time_interval route, return initial save time interval v…
CopyDemon Dec 30, 2023
504d9c1
add put_save_time_interval route, can use api to update save_time_int…
CopyDemon Dec 30, 2023
7f6660b
add save_time_interval param in router, add PutAppSettingRoute route
CopyDemon Dec 30, 2023
726cf32
keep autosave_interval to 5s
CopyDemon Dec 30, 2023
f638915
use server manager instence return fastapi app instence for test file…
CopyDemon Dec 30, 2023
8101949
after initial fastapi app use get_fast_api_app return fastapi instence
CopyDemon Dec 30, 2023
fee0614
use flowsheet class instences call function get_fast_api_app return f…
CopyDemon Dec 30, 2023
fc89355
remove print
CopyDemon Dec 30, 2023
5900726
when do put request to jjs flowsheet flowsheet manager also do a retu…
CopyDemon Dec 30, 2023
39a6d03
remove return message
CopyDemon Dec 30, 2023
43cfc7d
remove return message, rename new_save_time_interval to save_time_int…
CopyDemon Dec 30, 2023
33c0014
fix fastapi pytest
CopyDemon Dec 30, 2023
afd7b51
remove test model server the model server file is not exsit anymore
CopyDemon Dec 30, 2023
4546b06
1. move read flowsheet flowsheet name from flowsheet manager into if.…
CopyDemon Dec 31, 2023
c240161
remove comment out code which call old web server
CopyDemon Dec 31, 2023
93bb6f9
just try remove --pyargs to avoid __init__.py missing may revert it l…
CopyDemon Jan 4, 2024
837c977
remove dir path for pytest, try to see if this will resolve the __ini…
CopyDemon Jan 4, 2024
02a79c5
test try to install requriements-dev.txt in workflow, may repeat in a…
CopyDemon Jan 4, 2024
d5691e5
update workflow pytest exe command
CopyDemon Jan 4, 2024
79e98fe
revert back to old workflow with pytest run without path, will update…
CopyDemon Jan 4, 2024
0d2a98e
update echo out variant check if variant is dev revert this later
CopyDemon Jan 4, 2024
1dd558b
revert last commit print out variant, now know variant is standard
CopyDemon Jan 4, 2024
f036b62
test remove standard variant, only use dev check if it will install r…
CopyDemon Jan 4, 2024
76bfbe2
revert close variant standard, now know the issue __init__.py not fou…
CopyDemon Jan 5, 2024
1fed995
update in standard variant installed package, add fastapi uvicorn
CopyDemon Jan 5, 2024
672f03b
revert add fastapi and uvicorn in Install using pip part, it not reso…
CopyDemon Jan 6, 2024
d56ab1c
add install requirements-dev.txt in standard variant, fix this later …
CopyDemon Jan 6, 2024
43d7388
when get original flowsheet return a dict can be parse to json not fs…
CopyDemon Jan 6, 2024
2114822
update dof value shoule be 52
CopyDemon Jan 6, 2024
32f339b
fix fsvis test until test save
CopyDemon Jan 6, 2024
df54672
add params related to save, receive them from server manager when ini…
CopyDemon Jan 6, 2024
dd62750
receive save related params, pass down to server manager instence whe…
CopyDemon Jan 6, 2024
d98ec7f
initial new save related params for fastapi app
CopyDemon Jan 6, 2024
88a44d5
add basic save class includes create save location, and write to json…
CopyDemon Jan 6, 2024
d655ac1
update put flowshet router tag to update flowsheet
CopyDemon Jan 6, 2024
a2ce82a
initial save flowsheet class to handle all save related
CopyDemon Jan 6, 2024
83d63c2
add params related to save flowsheet
CopyDemon Jan 6, 2024
7ef9664
add new router PostSaveFlowsheet
CopyDemon Jan 6, 2024
4ea2a9f
revert standard varient run pip install requirements-dev.txt, it not …
CopyDemon Jan 6, 2024
ff776bc
remove kill_port from each test, this will cause pytest error when te…
CopyDemon Jan 6, 2024
5fea86d
remove print
CopyDemon Jan 6, 2024
87744d8
add clean up when exit the visualize clean up current flowsheet from …
CopyDemon Jan 8, 2024
85ecbfe
update fsvis add params and fns allow user to check running server li…
CopyDemon Jan 9, 2024
e74e778
add test and browser params to enable and disable the browser
CopyDemon Jan 9, 2024
fc028f3
pass browser param down to server manager and fastapi app, control on…
CopyDemon Jan 9, 2024
32bbfda
add test and browser params control browser on and off, test is use f…
CopyDemon Jan 9, 2024
f1306f3
temp close while loop, it use to catch keyboardinterrupt but it block…
CopyDemon Jan 9, 2024
6ac8357
minimize server_manager, since the flowsheet pass in memory no need t…
CopyDemon Jan 9, 2024
933209e
clean up test app fix test url with http:...., use correct way to ini…
CopyDemon Jan 9, 2024
0f6c882
update save end point add logic to populate save path and add version…
CopyDemon Jan 9, 2024
a0224a1
add clean-up param for example to easy remove running server list
CopyDemon Jan 9, 2024
5116c47
work save continue fix fsvis test
CopyDemon Jan 9, 2024
c3500be
default saved_flowsheet folder and its sub saved json file should not…
CopyDemon Jan 9, 2024
ebf636e
fix flowsheet manager get_jjs_flowsheet, when no update in else it re…
CopyDemon Jan 9, 2024
7980730
fix test app
CopyDemon Jan 10, 2024
074f5ea
work save continue fix fsvis pytest
CopyDemon Jan 11, 2024
e9e01db
in cyperss test update variant == dev to avoid ui not start issue, b…
CopyDemon Jan 11, 2024
f6c9ea6
work save the read saved file name == raw_name looks not woking, try …
CopyDemon Jan 11, 2024
9821d41
comment out the standar variant for test
CopyDemon Jan 11, 2024
fb10f55
update get req query param to flowsheet_name
CopyDemon Jan 13, 2024
2ef31be
work save, todo validate save param make sure user passed save is valid
CopyDemon Jan 13, 2024
5829d14
work save, has an error, the returned flowsheet name is not equal to …
CopyDemon Jan 13, 2024
f31ee91
update dependecy for pyproject for standard varient
CopyDemon Jan 17, 2024
a8456e6
add standard varient back fix not install requirements-dev.txt by add…
CopyDemon Jan 17, 2024
0d1db96
update pytest run command add --pyargs and package path back
CopyDemon Jan 17, 2024
af0b0ed
fix pytest command error add package path to the end
CopyDemon Jan 17, 2024
64a77ec
add missing package httpx
CopyDemon Jan 17, 2024
cf42a72
remove check repo only when variant == dev
CopyDemon Jan 17, 2024
1fc621e
remove & echo 'UI Server started' make sure the ui is running and ru…
CopyDemon Jan 17, 2024
1f283fa
try to update the command not use npm to start example
CopyDemon Jan 17, 2024
eed6828
let server run quite in background not block thread, sleep 30 sec giv…
CopyDemon Jan 17, 2024
9acb83a
add insall current repo when dev varient
CopyDemon Jan 17, 2024
41415b8
update the varient dev install order, and print out debug items py en…
CopyDemon Jan 17, 2024
33898d9
add bash and echo to debug
CopyDemon Jan 17, 2024
934b10a
degbug run install current not in action but in core
CopyDemon Jan 17, 2024
fba691f
remove debug line
CopyDemon Jan 20, 2024
3837433
remove step checkout current repo and put check variant back
CopyDemon Jan 20, 2024
86b4a91
add HTTPException, move diagnostics into try block
CopyDemon Jan 24, 2024
08f0f2f
use diagnostics toolbox build next steps and toolbox warnings caution…
CopyDemon Jan 24, 2024
2546ef1
build module statistics output
CopyDemon Jan 24, 2024
4632c6d
update diagnostics data export, move all diagnoststool box related ou…
CopyDemon Jan 26, 2024
b88bb19
add function zoomClearExtraFvElement to handle zoom in and zoom out n…
CopyDemon Feb 7, 2024
24bec4f
react build
CopyDemon Feb 7, 2024
15053d8
sync with main
CopyDemon Feb 7, 2024
b83aac8
work save react app add saveFSUrl
CopyDemon Feb 12, 2024
2320784
work save fastapi save route need to rewrite
CopyDemon Feb 12, 2024
9160afa
fix clean up function call location, instead of call in zoom btn clic…
CopyDemon Feb 15, 2024
50512c0
update cypress test
CopyDemon Feb 15, 2024
eee9684
rename test file
CopyDemon Feb 15, 2024
47ce8fe
add id to element for cypress test
CopyDemon Feb 15, 2024
24b9d1d
react run build
CopyDemon Feb 15, 2024
8a804dd
work save pytest save
CopyDemon Feb 21, 2024
299f6ba
fix flowsheet when zoom out too small and flowsheed disappear issue
CopyDemon Feb 22, 2024
d0c979d
idaes build
CopyDemon Feb 22, 2024
f47a5e7
remove maximize button from flowsheet panel
CopyDemon Feb 27, 2024
e338874
close maximize panel function since the only maximize btn in flowshee…
CopyDemon Feb 27, 2024
c88860b
remove import function maxmizePanele there will no maxmize btn
CopyDemon Feb 27, 2024
ab0bf5a
update class and style for stream table header right container to sty…
CopyDemon Feb 27, 2024
d477aaa
react run build
CopyDemon Feb 27, 2024
1463dde
since maximize btn been removed, remove test related to it
CopyDemon Feb 27, 2024
d476e44
merge main
CopyDemon Feb 27, 2024
6c39351
react run build
CopyDemon Feb 27, 2024
ce7b4a8
update pyproject fix .fv package cant find issue
CopyDemon Feb 27, 2024
4f077e6
work save
CopyDemon Feb 27, 2024
c2a45ca
Fixed an issue where repeatedly minimizing the panel caused the zoom …
CopyDemon Mar 1, 2024
8daada9
react run build
CopyDemon Mar 1, 2024
ec116de
fix bug when minimiz panel stream table hide field has duplicate list…
CopyDemon Mar 1, 2024
9f1d79a
react run build
CopyDemon Mar 1, 2024
343fbba
merge main
CopyDemon Mar 7, 2024
1f9a432
react build
CopyDemon Mar 7, 2024
3fb95f4
prepare fix the pytest
CopyDemon Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ runs:
- name: Check out repository
if: inputs.variant == 'dev'
uses: actions/checkout@v3
- name: install current repository
run: pip install .
- name: Install using pip (requirements-dev.txt)
if: inputs.variant == 'dev'
shell: bash -l {0}
run: |
pip install --progress-bar off -r requirements-dev.txt

run: pip install --progress-bar off -r requirements-dev.txt
- name: Install using pip (git+... URL)
if: inputs.variant == 'standard'
shell: bash -l {0}
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
runner-image: ubuntu-20.04
- os: win64
runner-image: windows-2022
steps:
steps:
- uses: IDAES/idaes-ui/.github/actions/install@main
with:
variant: ${{ matrix.install-variant }}
Expand Down Expand Up @@ -114,13 +114,18 @@ jobs:
package.json
package-lock.json
cypress.config.js

- name: Install node packages
run: npm install

- name: Start UI
run: npm run ui & echo "UI Server started"
run: |
python -m idaes_ui.fv.example &
sleep 30

- name: Cypress run
uses: cypress-io/github-action@v5
with:
wait-on-timeout: 20
wait-on-timeout: 50
command: npm run test
browser: chrome
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ dmypy.json
# auto generated files
sample_visualization.json
shared_variable.json
*.pickle
saved_flowsheet/

# cypress
screenshots
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class MainFV {
baseUrl:string;
getFSUrl:string;
putFSUrl:string;
saveFSUrl:string;
getAppSettingUrl:string;
model:any;
paper:any;
_is_graph_changed:boolean;
Expand All @@ -43,6 +45,7 @@ export class MainFV {
_save_time_interval:any;
stream_table:any;
toolbar: any;
cleanToolBarEvent: any;


constructor (flowsheetId:any, port:string | number, isFvShow:boolean, isVariablesShow:boolean, isStreamTableShow:boolean) {
Expand All @@ -53,9 +56,11 @@ export class MainFV {
this.isStreamTableShow = isStreamTableShow;

//Gerneate url for fetch data
this.baseUrl = `http://localhost:${port}`
this.getFSUrl = VITE_MODE === "dev" ? `${this.baseUrl}/fs?id=${flowsheetId}` : `/fs?id=${flowsheetId}`;
this.putFSUrl = VITE_MODE === "dev" ? `${this.baseUrl}/fs?id=${flowsheetId}` : `/fs?id=${flowsheetId}`;
this.baseUrl = `http://localhost:${port}`;
this.getFSUrl = `${this.baseUrl}/api/get_fs?get_which=flowsheet`;
this.putFSUrl = `${this.baseUrl}/api/put_fs`;
this.saveFSUrl = `${this.baseUrl}/api/post_save_flowsheet`;
this.getAppSettingUrl = `${this.baseUrl}/api/get_app_setting`;

//Define model
this.model = {}
Expand All @@ -70,35 +75,40 @@ export class MainFV {
// Setting name (key) that defines the save model time interval
this._save_time_interval_key = 'save_time_interval';
this._default_save_time_interval = 5000; // Default time interval
this._save_time_interval = this.getSaveTimeInterval();
this._save_time_interval = this.getSaveTimeInterval(this.getAppSettingUrl);
this.setupGraphChangeChecker(this._save_time_interval, flowsheetId);

//fetch model data from python server, once get data then render model and stream table
//default is from sample_visualization if no ?example=1 etc. in url
//define if fetch from example
this.setGetFSUrl();

/**
* @param
*/
axios.get(this.getFSUrl)
.then((response) => {
console.log(this.getFSUrl)
//get data from python server /fs
this.model = response.data;
if(response.data._old && response.data._new){
this.model = response.data._new
}else{
this.model = response.data;
}

//debug when flowsheet has no position it should not stack on each other
isDevTest && this.debug_removeFlowsheetPosition(this.model);
//render model
if(isFvShow) this.renderModel(this.model); //this only run when fv is show
//render stream table
//if statment control when stream table not show the stream table should not render
if(isStreamTableShow) this.stream_table = new StreamTable(this, this.model);
// new this.toolbar
this.toolbar = new Toolbar(this, this.paper, this.stream_table, this.flowsheetId, this.getFSUrl,this.putFSUrl, this.isFvShow);
// get toolbar event cleanup function
this.cleanToolBarEvent = this.toolbar.cleanUpEvent;
})
.catch((error) => {
console.log(error.message);
console.log(error.response.status);
});

// cleanup #fv container extra joint paper element
this.fvExtraContentCleanUp()
}

/**
Expand Down Expand Up @@ -224,15 +234,12 @@ export class MainFV {
});
}

/**
* Get the save time interval value from the application's setting block.
*/
getSaveTimeInterval() {
//question:
//this is the old way to write setting_url question its key=" then concat, should I keep "?
//let settings_url = `${this.baseUrl}/setting?setting_key="`.concat(this._save_time_interval_key);

let settings_url = `${this.baseUrl}/setting?setting_key=${this._save_time_interval_key}`;
/**
* @description Get the save time interval value from the application's setting block.
* @returns save_time_interval
*/
getSaveTimeInterval(setting_url:string) {
let settings_url = `${this.baseUrl}/api/get_app_setting`;
let save_time_interval = this._default_save_time_interval;

axios.get(settings_url, {
Expand All @@ -241,7 +248,7 @@ export class MainFV {
}
})
.then((response) => {
if (response.data.value != 'None') {
if (response.data.value) {
save_time_interval = response.data.value;
} else {
this.informUser(
Expand Down Expand Up @@ -282,6 +289,7 @@ export class MainFV {

var graphChangedChecker = setInterval(() => {
if (this._is_graph_changed) {
console.log(this.paper.graph)
this.saveModel(flowsheet_url, this.paper.graph);
// reset flag
this._is_graph_changed = false;
Expand All @@ -304,18 +312,50 @@ export class MainFV {
* @param model The model to save
*/
saveModel(url:any, model:any) {
let clientData = JSON.stringify(model.toJSON());
axios.put(url, clientData, {
let modelData = {
"flowsheet_type": "jjs_fs",
"flowsheet": model //data type in python is dict
};
axios.put(url, JSON.stringify(modelData), {
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => {
console.log(`saved`)
console.log(response.data)
this.informUser(0, "Saved new model values");
})
.catch((error) => {
this.informUser(2, "Fatal error: cannot save current model: " + error);
});

axios.post(this.saveFSUrl, JSON.stringify({save_flowsheet_model:true})).then(res=>res).then(data => console.log(data))
}

/**
* @Description This function help check if fv has mutiple children,
* if has will remove all children and keep the last one.
*
* @Reason When react render, will create a new instence of MainFv,
* it will create a new fv display stack under the old one.
* this behivor cause zoom in and out btn not working so we need to clear all
* fv display other than the last one.
*
* @returns void
*/
fvExtraContentCleanUp(){
let fv = document.getElementById("fv");

//validation if fv and fv has mutiple child
if(!fv || fv.childNodes.length <= 1){
return;
}

//get fv last child and remove others
let lastFvChild = fv.childNodes[fv?.childNodes.length - 1]
while(fv.firstChild !== fv.lastChild){
fv.removeChild(fv.firstChild as Node)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class StreamTable {
// Get the hide fields list
const hide_fields_list = document.querySelector("#hide-fields-list");

// reset hide_fields_list innerHTML to empty for prevent accumulating duplicate list items.
if(hide_fields_list){
hide_fields_list.innerHTML = "";
}
// Specify the column headers
let columns = stream_table_data["columns"];
let column_defs = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export class Toolbar {
getFSUrl: string;
putFSUrl:string;
isFvShow:boolean;
zoomRate:number;

toggleStreamNameBtn:HTMLElement | undefined;
toggleLabelsBtn:HTMLElement | undefined;

zoomInBtn:HTMLElement | undefined;
zoomOutBtn:HTMLElement | undefined;
zoomToFitBtn: HTMLElement | undefined;
zoomFitBtn: HTMLElement | undefined;
zoomInHandler: (() => void) | undefined;
zoomOutHandler: (() => void) | undefined;
zoomFitHandler: (() => void) | undefined;

constructor(app:any, paper:any, stream_table:any | undefined, flowsheetId:string, getFSUrl:string, putFSUrl:string, isFvShow:boolean) {
//initial arguments
Expand All @@ -48,6 +52,10 @@ export class Toolbar {
this.getFSUrl = getFSUrl;
this.putFSUrl = putFSUrl;
this.isFvShow = isFvShow;
this.zoomRate = 0.2;
this.zoomInHandler = undefined;
this.zoomOutHandler = undefined;
this.zoomFitHandler = undefined;
// this.setupPageToolbar();
// this.setupFlowsheetToolbar();

Expand All @@ -60,9 +68,16 @@ export class Toolbar {

//call & register click event to save flowsheet
this.registerEventSave(this.putFSUrl)


/**
* Tool bar zoom in out and fit
*/
//isFvShow repersent stream name, labels, zoom in, zoom out, zoom fit btn
//if !isFvShow these event has no need to register event

this.zoomInBtn = document.querySelector("#zoom-in-btn") as HTMLElement;
this.zoomOutBtn = document.querySelector("#zoom-out-btn") as HTMLElement;
this.zoomFitBtn = document.querySelector("#zoom-to-fit") as HTMLElement;
if(isFvShow){
/**
* Tool bar stream names toggle
Expand All @@ -85,14 +100,11 @@ export class Toolbar {
/**
* Tool bar zoom in out and fit
*/
//initial zoom btn from selector assign to this
this.zoomInBtn = document.querySelector("#zoom-in-btn") as HTMLElement;
this.zoomOutBtn = document.querySelector("#zoom-out-btn") as HTMLElement;
this.zoomToFitBtn = document.querySelector("#zoom-to-fit") as HTMLElement;
//registerZoomEvent
//call registerZoomEvent function, register 3 zoom events to zoom in zoom out zoom to fit btn on dom
//when button is not exist it should not register event, one example is isFvShow = false
if(this.zoomInBtn && this.zoomOutBtn && this.zoomToFitBtn){
this.registerZoomEvent(this.zoomInBtn, this.zoomOutBtn, this.zoomToFitBtn);
if(this.zoomInBtn && this.zoomOutBtn && this.zoomFitBtn){
this.registerZoomEvent(this.zoomInBtn, this.zoomOutBtn, this.zoomFitBtn);
}
}
}
Expand All @@ -104,21 +116,32 @@ export class Toolbar {
* @param zoomOutBtn HTML element, selected by ID zoom-out-btn
* @param zoomToFitBtn HTML element, selected by ID zoom-to-fit
*/
registerZoomEvent(zoomInBtn:HTMLElement, zoomOutBtn:HTMLElement, zoomToFitBtn:HTMLElement){
// Zoom in event listener
zoomInBtn.addEventListener("click", () => {
this._paper.paperScroller.zoom(0.2, { max: 4 });
});
registerZoomEvent(zoomInBtn:HTMLElement, zoomOutBtn:HTMLElement, zoomFitBtn:HTMLElement){
this.zoomInHandler = () => this.zoomInEvent(this._paper.paperScroller, this.zoomRate);
this.zoomOutHandler = () => this.zoomOutEvent(this._paper.paperScroller, this.zoomRate);
this.zoomFitHandler = () => this.zoomFitEvent();

// Zoom in event listener
zoomInBtn.addEventListener("click", this.zoomInHandler as EventListener);
// Zoom out event listener
zoomOutBtn.addEventListener("click", () => {
this._paper.paperScroller.zoom(-0.2, { min: 0.2 });
});

zoomOutBtn.addEventListener("click", this.zoomOutHandler as EventListener);
// Zoom to fit event listener
zoomToFitBtn.addEventListener("click", () => {
this._paper.zoomToFit();
});
zoomFitBtn.addEventListener("click", this.zoomFitHandler as EventListener);
}

/**
* create zoom events handler
*/
zoomInEvent(paperScroller:any, zoomRate:number){
paperScroller.zoom(zoomRate, { max: 100 });
}

zoomOutEvent(paperScroller:any, zoomRate:number){
paperScroller.zoom(-(zoomRate), { min: 0.01 });
}

zoomFitEvent(){
this._paper.zoomToFit();
}

/**
Expand Down Expand Up @@ -217,4 +240,30 @@ export class Toolbar {
this._app.saveModel(save_url, this._paper.graph);
});
}

/**
* Description: clean up event, when react update state new class instance will be created
* event listener will double registered, have to remove them to prevent multiple event trigger at one click issue.
*
* this remove event by clone current node and replace the old node, way to reset event.
*/

cleanUpEvent(){
let zoomInBtn = document.getElementById('zoom-in-btn');
let zoomOutBtn = document.getElementById('zoom-out-btn');
let zoomFitBtn = document.getElementById('zoom-to-fit');

if(zoomInBtn){
let zoomInBtnClone = zoomInBtn.cloneNode(true);
zoomInBtn.parentNode!.replaceChild(zoomInBtnClone, zoomInBtn);
};
if(zoomOutBtn){
let zoomOutBtnClone = zoomOutBtn.cloneNode(true);
zoomOutBtn.parentNode!.replaceChild(zoomOutBtnClone, zoomOutBtn);
};
if(zoomFitBtn){
let zoomFitBtnClone = zoomFitBtn.cloneNode(true);
zoomFitBtn.parentNode!.replaceChild(zoomFitBtnClone, zoomFitBtn);
};
}
}
Loading
Loading