diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..3e417baa2 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,28 @@ +name: Build and Deploy +on: + push: + branches: + - master + workflow_dispatch: +permissions: + contents: write +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v4.2.2 + with: + persist-credentials: false + + - name: Install and Build 🔧 + run: | + npm install + npm run ghpages + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4.7.2 + with: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: gh_pages + CLEAN: true diff --git a/.gitignore b/.gitignore index d3d7b7c0e..b2655ec38 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ demo/omero_figure/ demo/figure.js demo/index.html node_modules/ +gh_pages/ _site dist omero_figure.egg-info diff --git a/README.rst b/README.rst index d86f84a8b..70260068a 100644 --- a/README.rst +++ b/README.rst @@ -12,7 +12,11 @@ OMERO.figure ============ -An OMERO.web app for creating figures from images in OMERO. +An app for creating figures from images. + +The app can be used standalone with OME-Zarr images or installed within OMERO.web to work with OMERO images. + +The standalone app is available at `https://ome.github.io/omero-figure/ `_. For full details see `SUPPORT.md `_. @@ -182,55 +186,63 @@ Install Node from https://nodejs.org, then: $ cd omero-figure $ npm install +You can deploy the app during development in two ways: using the vite dev server or from OMERO.web. + + +Deploying with vite dev server +****************************** + To serve the app at http://localhost:8080/ using the vite dev server (this will automatically refresh the page when changes are saved): :: - $ npm run start + $ npm run dev # or npm run start + +The app will run as a standalone app that can load OME-Zarr images. +A global variable `APP_SERVED_BY_OMERO` will be `false` and this is used +to determine the behaviour of various features such as File Open/Save +and the figure Export dialog. If you are editing the Shape-Editor code, you can view the test page at http://localhost:8080/shapeEditorTest.html -CORS -**** - -During development, we load and save figure files to an omero-web server. -You will need to have CORS enabled on your local omero-web server at -http://localhost:4080/ and be logged in already. -This URL can be edited in `src/index.html`. +Deploying from OMERO.web +************************ -You MUST access the figure app at http://localhost:8080/ (NOT http://127.0.0.1:8080/) -for CORS to work. - -NB: in general, POST actions such as saving of figure files or exporting figures doesn't -yet work with the dev server. To test these actions, build the app as described below: +To deploy the app from OMERO.web during development, you should checkout the code +and install from there into your OMERO.web python environment: +:: -Build ------ + $ cd omero-figure + $ pip install -e . -To build the app: +Then configure your local OMERO.web as described above and restart OMERO.web. +You will need to build the app with: :: - $ npm run build - -This compiles index.html and other static assets into correct locations to be -served by the Django `omero-web` server. + $ npm run build -To serve this on a local omero-web, set config as above and install with: +To build whenever changes are saved within the `src/` directory: :: - $ pip install -e . + $ npm run watch -In order to build whenever changes are saved within the `src/` directory: +You will need to refresh the OMERO.figure app to see changes when using this workflow. -:: - $ npm run watch +Deploying the standalone app +---------------------------- + +The standalone app is deployed to GitHub pages at https://ome.github.io/omero-figure/ via a GitHub action defined in ``.github/workflows/pages.yml`` which acts on push to the `master` branch. +The action then builds the app and pushes the built files to the `gh-pages` branch. + +To deploy the app from your own fork, you can push to your own `master` branch and set up GitHub pages to deploy from the +root of your `gh-pages` branch. Release process diff --git a/deploy_ghpages.sh b/deploy_ghpages.sh new file mode 100755 index 000000000..79b75a458 --- /dev/null +++ b/deploy_ghpages.sh @@ -0,0 +1,7 @@ + +# To ensure that the gh-pages job doesn't try to build a jekyll site +# (and ignore files in /assets), we create a .nojekyll file in the +# ./gh_pages/ output dir. The pages.yml workflow copies all of that dir +# to the gh-pages branch. + +touch gh_pages/.nojekyll diff --git a/omero_figure/views.py b/omero_figure/views.py index 04dd9d2e8..39f7b24b8 100644 --- a/omero_figure/views.py +++ b/omero_figure/views.py @@ -117,6 +117,8 @@ def index(request, file_id=None, conn=None, **kwargs): # Load the template html and replace OMEROWEB_INDEX template = loader.get_template("omero_figure/index.html") html = template.render({}, request) + html = html.replace('const APP_SERVED_BY_OMERO = false;', + 'const APP_SERVED_BY_OMERO = true;') omeroweb_index = reverse("index") figure_index = reverse("figure_index") ping_url = reverse("keepalive_ping") @@ -154,8 +156,10 @@ def index(request, file_id=None, conn=None, **kwargs): # update links to static files static_dir = static.static('omero_figure/') - html = html.replace('href="/', 'href="%s' % static_dir) - html = html.replace('src="/', 'src="%s' % static_dir) + html = html.replace('href="/assets', + 'href="%sassets' % static_dir) + html = html.replace('src="/assets', + 'src="%sassets' % static_dir) html = html.replace('const STATIC_DIR = "";', 'const STATIC_DIR = "%s";' % static_dir[0:-1]) diff --git a/package.json b/package.json index 96784287d..8c3ebae0a 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "description": "OMERO figure creation app", "main": "index.js", "scripts": { + "dev": "vite", "start": "vite", "build": "vite build --emptyOutDir && ./deploy_build.sh", + "ghpages": "vite build --outDir ../gh_pages && ./deploy_ghpages.sh", "test": "echo \"Error: no test specified\" && exit 1", "watch": "watch 'npm run build' ./src" }, diff --git a/src/css/figure.css b/src/css/figure.css index da83b0358..32876e348 100644 --- a/src/css/figure.css +++ b/src/css/figure.css @@ -1059,7 +1059,7 @@ text-align: left; } - .lutOption span { + .lutOption span, .lutOption img { width: 85px; display: inline-block; } @@ -1074,6 +1074,7 @@ /* NB: when updating png, consider using different name to avoid cache */ background-size: 100% var(--pngHeight); background-image: var(--lutPng); + background-position: var(--bgPos); background-repeat: no-repeat; image-rendering: pixelated; /* Universal support since 2021 */ } diff --git a/src/index.html b/src/index.html index 11c0c824a..447d61228 100644 --- a/src/index.html +++ b/src/index.html @@ -5,9 +5,12 @@ OMERO.figure