Skip to content

Commit

Permalink
Merge branch 'master' into settings-wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alizenart committed Jan 22, 2024
2 parents 4caddca + 5aa3faf commit f55cb9a
Show file tree
Hide file tree
Showing 599 changed files with 7,235 additions and 1,999 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: build-and-test

on:
push:
pull_request:
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v3
with:
distribution: 'liberica'
java-version: '17.0'
java-package: jdk+fx

- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: package-lock.json

- name: Git Init
run: git submodule update --init --recursive

- name: Build and Test
run: |
sbt -v update compile
sbt -v scalastyle coffeelint test
- uses: actions/cache@v3
id: restore-build
with:
path: ./*
key: ${{ github.sha }}

deploy:
runs-on: ubuntu-latest
needs: build-and-test
if: ${{ github.ref == 'refs/heads/scrape-test' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/production' }}
environment: Deployments
env:
AWS_REGION: 'us-east-1'
AWS_ROLE_TO_ASSUME: 'arn:aws:iam::922513866616:role/Galapagos-AWS-Deploy'

steps:
- uses: actions/cache@v3
id: restore-build
with:
path: ./*
key: ${{ github.sha }}

- uses: actions/setup-java@v3
with:
distribution: 'liberica'
java-version: '17.0'
java-package: jdk+fx

- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: package-lock.json

- name: Configure AWS Credentials
id: creds
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
role-session-name: 'GitHub-Actions-Galapagos-AWS-Deploy'
output-credentials: true

- name: Verify AWS Credentials
run: |
aws sts get-caller-identity
- name: Scrape
run: |
sbt scrapePlay
cp -Rv public/modelslib/ target/play-scrape/assets/
cp -Rv public/nt-modelslib/ target/play-scrape/assets/
- name: Upload
env:
CREDENTIALS_FROM_ENVIRONMENT: 'true'
BUILD_SERVER: 'true'
BUILD_BRANCH: ${{ github.ref_name }}
AWS_ACCESS_KEY_ID: ${{ steps.creds.outputs.aws-access-key-id }}
AWS_SECRET_KEY: ${{ steps.creds.outputs.aws-secret-access-key }}
AWS_SESSION_TOKEN: ${{ steps.creds.outputs.aws-session-token }}
run: |
sbt scrapeUpload
67 changes: 0 additions & 67 deletions Jenkinsfile

This file was deleted.

7 changes: 6 additions & 1 deletion app/assets/javascripts/alert-display.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AlertDisplay
show: (_, title, message, frames) ->
if @get('isActive')
@set('title', "#{@get('title')} / #{title}")
@set('message', "#{@get('message')}<br/><br/>Next message: #{message}")
@set('message', "#{message}<br/><br/>Next message: #{@get('message')}")
else
@set('title', title)
@set('message', message)
Expand Down Expand Up @@ -233,6 +233,11 @@ class AlertDisplay
message = AlertDisplay.makeCompilerErrorMessage(errors).join('<br/>')
if source is 'compile-fatal'
@_ractive.set('isDismissable', false)
message = if not @_ractive.get('isActive') then message else
"""There was an error compiling the model's code:<br/><br/>
#{message}<br/><br/>
The below errors were generated by the widgets, but they may be
caused by the above compilation issues in the model's code."""
@reportError(message)

return
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/beak/session-lite.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DEFAULT_REDRAW_DELAY = 1000 / 30
MAX_REDRAW_DELAY = 1000
REDRAW_EXP = 2

NETLOGO_VERSION = '2.10.7'
NETLOGO_VERSION = '2.11.0'

# performance.now gives submillisecond timing, which improves the event loop
# for models with submillisecond go procedures. Unfortunately, iOS Safari
Expand Down Expand Up @@ -221,9 +221,10 @@ class SessionLite
@widgetController.ractive.set('isStale', false)
@widgetController.ractive.set('lastCompiledCode', code)
@widgetController.ractive.set('lastCompileFailed', false)
@widgetController.viewController.resetModel()
@widgetController.redraw()
@widgetController.freshenUpWidgets(oldWidgets, globalEval(res.widgets))
viewWidget = @widgetController.widgets().find(({ type }) -> type is 'view')
@widgetController.viewController.resetModel(viewWidget)

globalEval(res.model.result)
workspace.i18nBundle.switch(@locale)
Expand Down
42 changes: 38 additions & 4 deletions app/assets/javascripts/beak/widgets/draw/view-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,41 @@ import { LinkDrawer } from "./link-drawer.js"

AgentModel = tortoise_require('agentmodel')

# (Array[(Object[Any], String)], Any) => Unit
entwine = (objKeyPairs, value) ->

backingValue = value

for [obj, key, tag] in objKeyPairs
Object.defineProperty(obj, key, {
configurable: true
get: -> backingValue
set: (newValue) -> backingValue = newValue
})

return

# (Widgets.View, ViewController.View) => Unit
entwineDimensions = (viewWidget, modelView) ->

translations = {
maxPxcor: "maxpxcor"
, maxPycor: "maxpycor"
, minPxcor: "minpxcor"
, minPycor: "minpycor"
, patchSize: "patchsize"
, wrappingAllowedInX: "wrappingallowedinx"
, wrappingAllowedInY: "wrappingallowediny"
}

for wName, mName of translations
entwine([[viewWidget.dimensions, wName], [modelView, mName]], viewWidget.dimensions[wName])

return

class ViewController
constructor: (@container, fontSize) ->
@view = new View(fontSize)
constructor: (@container, viewWidget) ->
@view = new View(viewWidget.fontSize)
@turtleDrawer = new TurtleDrawer(@view)
@drawingLayer = new DrawingLayer(@view, @turtleDrawer, () => @repaint())
@patchDrawer = new PatchDrawer(@view)
Expand All @@ -20,7 +52,7 @@ class ViewController
@mouseY = 0
@initMouseTracking()
@initTouchTracking()
@resetModel()
@resetModel(viewWidget)
@repaint()

mouseXcor: => @view.xPixToPcor(@mouseX)
Expand Down Expand Up @@ -78,9 +110,11 @@ class ViewController

return

resetModel: ->
resetModel: (viewWidget) ->
@model = new AgentModel()
@model.world.turtleshapelist = defaultShapes
entwineDimensions(viewWidget, @model.world)
entwine([[viewWidget, "fontSize"], [@view, "fontSize"]], viewWidget.fontSize)

repaint: ->
@view.transformToWorld(@model.world)
Expand Down
40 changes: 3 additions & 37 deletions app/assets/javascripts/beak/widgets/initialize-ui.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ initializeUI = (containerArg, widgets, code, info,
preventScroll: true
})

viewModel = widgets.find(({ type }) -> type is 'view')
viewWidget = widgets.find(({ type }) -> type is 'view')

ractive.set('primaryView', viewModel)
viewController = new ViewController(container.querySelector('.netlogo-view-container'), viewModel.fontSize)

entwineDimensions(viewModel, viewController.model.world)
entwine([[viewModel, "fontSize"], [viewController.view, "fontSize"]], viewModel.fontSize)
ractive.set('primaryView', viewWidget)
viewController = new ViewController(container.querySelector('.netlogo-view-container'), viewWidget)

configs = genConfigs(ractive, viewController, container, compiler)
controller = new WidgetController(ractive, viewController, configs)
Expand All @@ -64,35 +61,4 @@ initializeUI = (containerArg, widgets, code, info,

controller

# (Array[(Object[Any], String)], Any) => Unit
entwine = (objKeyPairs, value) ->

backingValue = value

for [obj, key] in objKeyPairs
Object.defineProperty(obj, key, {
get: -> backingValue
set: (newValue) -> backingValue = newValue
})

return

# (Widgets.View, ViewController.View) => Unit
entwineDimensions = (viewWidget, modelView) ->

translations = {
maxPxcor: "maxpxcor"
, maxPycor: "maxpycor"
, minPxcor: "minpxcor"
, minPycor: "minpycor"
, patchSize: "patchsize"
, wrappingAllowedInX: "wrappingallowedinx"
, wrappingAllowedInY: "wrappingallowediny"
}

for wName, mName of translations
entwine([[viewWidget.dimensions, wName], [modelView, mName]], viewWidget.dimensions[wName])

return

export default initializeUI
7 changes: 7 additions & 0 deletions app/assets/javascripts/beak/widgets/ractives/widget.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ RactiveWidget = RactiveDraggableAndContextable.extend({
uniqueEvents =
events.reduce(((acc, x) -> if not acc.find((y) -> y.type is x.type)? then acc.concat([x]) else acc), [])

# Special casing this feels a bit silly, but it works, and given the special casing for plots, I guess it's
# par for the course. Necessary because if the redraw happens before all changes are applied (topology and
# world coordinates) then the unapplied stuff is lost. -Jeremy B December 2023
uniqueEvents.sort( (event1, event2) ->
if (event1.type is 'redrawView') then 1 else if (event2.type is 'redrawView') then -1 else 0
)

for event in uniqueEvents
realEvent =
if event.type is "recompile-for-plot"
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/beak/widgets/widget-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class WidgetController
createWidget: (widgetType, x, y) ->

rect = document.querySelector('.netlogo-widget-container').getBoundingClientRect()
adjustedX = Math.round(x - rect.left)
adjustedY = Math.round(y - rect.top)
adjustedX = Math.round(x - (rect.left + window.scrollX ) )
adjustedY = Math.round(y - (rect.top + window.scrollY) )
base = { left: adjustedX, top: adjustedY, type: widgetType }
mixin = defaultWidgetMixinFor(widgetType, adjustedX, adjustedY, @_countByType)
widget = Object.assign(base, mixin)
Expand Down
Loading

0 comments on commit f55cb9a

Please sign in to comment.