<commit_before>asset.require("./static_server")

local guiCustomization = asset.require("customization/gui")

-- Select which commit hashes to use for the frontend and backend
local frontendHash = "1823d1b030e3e8ecc768f936e78496ad43adcf62"
local dataProvider = "data.openspaceproject.com/files/webgui"

local frontend = asset.syncedResource({
  Identifier = "WebGuiFrontend",
  Name = "Web Gui Frontend",
  Type = "UrlSynchronization",
  Url = dataProvider .. "/frontend/" ..  frontendHash .. "/frontend.zip"
})

asset.onInitialize(function ()
  -- Unzip the frontend bundle
  local dest = frontend .. "frontend"
  if not openspace.directoryExists(dest) then
    openspace.unzipFile(frontend .. "frontend.zip", dest, true)
  end

  -- Disable the server, add production gui endpoint, and restart server.
  -- The temporary disabling avoids restarting the server on each property change.
  -- TODO: Add a trigger property to the module to restart the server "manually"
  -- and remove automatic restart on each property change,
  -- since frequent restarting seems to be unstable on mac.

  local enabled = openspace.getPropertyValue("Modules.WebGui.ServerProcessEnabled")
  openspace.setPropertyValueSingle("Modules.WebGui.ServerProcessEnabled", false)

  local directories = openspace.getPropertyValue("Modules.WebGui.Directories")
  directories[#directories + 1] = "frontend"
  directories[#directories + 1] = frontend .. "frontend"

  openspace.setPropertyValueSingle("Modules.WebGui.Directories", directories)
  openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "frontend")
  openspace.setPropertyValueSingle("Modules.WebGui.ServerProcessEnabled", enabled)

  -- The GUI contains date and simulation increment,
  -- so let's remove these from the dashboard.
  if openspace.getPropertyValue("Modules.CefWebGui.Visible") then
    if openspace.hasProperty("Dashboard.Date.Enabled") then
      openspace.setPropertyValueSingle("Dashboard.Date.Enabled", false)
    end
    if openspace.hasProperty("Dashboard.SimulationIncrement.Enabled") then
      openspace.setPropertyValueSingle("Dashboard.SimulationIncrement.Enabled", false)
    end
  end
end)

asset.onDeinitialize(function ()
  -- Remove the frontend endpoint
  local directories = openspace.getPropertyValue("Modules.WebGui.Directories")
  local newDirectories = {};

  -- @TODO(maci, 2019-08-23) see message below
  --openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "")

  for i = 0, #directories, 2 do
    -- @TODO(abock, 2019-08-20) The explicit check for directories[i] is a workaround
    -- for an error that was otherwise thrown when directories[i] was nil
    if (directories[i] and string.find(directories[i], "frontend") == nil) then
      newDirectories[#newDirectories + 1] = directories[i]
      newDirectories[#newDirectories + 1] = directories[i + 1]
    end
  end
  -- @TODO(maci, 2019-08-23) setting this value on exit was causing the server to restart
  -- on macos, which in turn, stopped the application from exiting.
  -- need to address in webguimodule.cpp
  --openspace.setPropertyValueSingle("Modules.WebGui.Directories", newDirectories)
end)

function setCefRoute(route)
  local port = 4680
  -- As a developer, you can manually serve the webgui from port 4690
  -- with the command `npm start` in the web gui repository
  if guiCustomization.webguiDevelopmentMode then
    port = 4690
  end
  openspace.setPropertyValueSingle(
    "Modules.CefWebGui.GuiUrl",
    "http://127.0.0.1:" .. port .. "/frontend/#/" .. route
  )
end


asset.export("setCefRoute", setCefRoute)

asset.meta = {
  Name = "WebGUI",
  Version = "0.1",
  Description = [[ insert CEF rant ]],
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
<commit_msg>Update web gui hash to newest version of the gui<commit_after>asset.require("./static_server")

local guiCustomization = asset.require("customization/gui")

-- Select which commit hashes to use for the frontend and backend
local frontendHash = "ea33990de2e1477ecafa89861cf6f65e4c2fd46d"
local dataProvider = "data.openspaceproject.com/files/webgui"

local frontend = asset.syncedResource({
  Identifier = "WebGuiFrontend",
  Name = "Web Gui Frontend",
  Type = "UrlSynchronization",
  Url = dataProvider .. "/frontend/" ..  frontendHash .. "/frontend.zip"
})

asset.onInitialize(function ()
  -- Unzip the frontend bundle
  local dest = frontend .. "frontend"
  if not openspace.directoryExists(dest) then
    openspace.unzipFile(frontend .. "frontend.zip", dest, true)
  end

  -- Disable the server, add production gui endpoint, and restart server.
  -- The temporary disabling avoids restarting the server on each property change.
  -- TODO: Add a trigger property to the module to restart the server "manually"
  -- and remove automatic restart on each property change,
  -- since frequent restarting seems to be unstable on mac.

  local enabled = openspace.getPropertyValue("Modules.WebGui.ServerProcessEnabled")
  openspace.setPropertyValueSingle("Modules.WebGui.ServerProcessEnabled", false)

  local directories = openspace.getPropertyValue("Modules.WebGui.Directories")
  directories[#directories + 1] = "frontend"
  directories[#directories + 1] = frontend .. "frontend"

  openspace.setPropertyValueSingle("Modules.WebGui.Directories", directories)
  openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "frontend")
  openspace.setPropertyValueSingle("Modules.WebGui.ServerProcessEnabled", enabled)

  -- The GUI contains date and simulation increment,
  -- so let's remove these from the dashboard.
  if openspace.getPropertyValue("Modules.CefWebGui.Visible") then
    if openspace.hasProperty("Dashboard.Date.Enabled") then
      openspace.setPropertyValueSingle("Dashboard.Date.Enabled", false)
    end
    if openspace.hasProperty("Dashboard.SimulationIncrement.Enabled") then
      openspace.setPropertyValueSingle("Dashboard.SimulationIncrement.Enabled", false)
    end
  end
end)

asset.onDeinitialize(function ()
  -- Remove the frontend endpoint
  local directories = openspace.getPropertyValue("Modules.WebGui.Directories")
  local newDirectories = {};

  -- @TODO(maci, 2019-08-23) see message below
  --openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "")

  for i = 0, #directories, 2 do
    -- @TODO(abock, 2019-08-20) The explicit check for directories[i] is a workaround
    -- for an error that was otherwise thrown when directories[i] was nil
    if (directories[i] and string.find(directories[i], "frontend") == nil) then
      newDirectories[#newDirectories + 1] = directories[i]
      newDirectories[#newDirectories + 1] = directories[i + 1]
    end
  end
  -- @TODO(maci, 2019-08-23) setting this value on exit was causing the server to restart
  -- on macos, which in turn, stopped the application from exiting.
  -- need to address in webguimodule.cpp
  --openspace.setPropertyValueSingle("Modules.WebGui.Directories", newDirectories)
end)

function setCefRoute(route)
  local port = 4680
  -- As a developer, you can manually serve the webgui from port 4690
  -- with the command `npm start` in the web gui repository
  if guiCustomization.webguiDevelopmentMode then
    port = 4690
  end
  openspace.setPropertyValueSingle(
    "Modules.CefWebGui.GuiUrl",
    "http://127.0.0.1:" .. port .. "/frontend/#/" .. route
  )
end


asset.export("setCefRoute", setCefRoute)

asset.meta = {
  Name = "WebGUI",
  Version = "0.1",
  Description = [[ insert CEF rant ]],
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}

{'fraction_non_alphanumeric': 0.10741956664478004, 'fraction_numerical': 0.019566644780039395, 'mean_word_length': 4.296244784422809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '943765', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2280, 'n_words': 623}