src/Tools/Find_Facts/src/find_facts.scala
changeset 82111 80b00abb9aac
parent 82107 6c3b7d1f2115
child 82113 b636cad7b684
equal deleted inserted replaced
82110:9b4e021cfd08 82111:80b00abb9aac
   883   }
   883   }
   884 
   884 
   885 
   885 
   886   /* web */
   886   /* web */
   887 
   887 
       
   888   val web_html: Path = Path.basic("index").html
       
   889 
   888   val web_sources: Path = Path.explode("$FIND_FACTS_HOME/web")
   890   val web_sources: Path = Path.explode("$FIND_FACTS_HOME/web")
   889   val default_web_dir: Path = Path.explode("$FIND_FACTS_HOME_USER/web")
   891   val default_web_dir: Path = Path.explode("$FIND_FACTS_HOME_USER/web")
   890 
   892 
   891   def build_html(web_dir: Path = default_web_dir, progress: Progress = new Progress): String = {
   893   def build_html(
       
   894     output_file: Path,
       
   895     web_dir: Path = default_web_dir,
       
   896     progress: Progress = new Progress
       
   897   ): Unit = {
   892     Isabelle_System.copy_dir(web_sources, web_dir, direct = true)
   898     Isabelle_System.copy_dir(web_sources, web_dir, direct = true)
   893     val logo = Bytes.read(web_dir + Path.explode("favicon.ico"))
   899     val logo = Bytes.read(web_dir + Path.explode("favicon.ico"))
   894     val project =
   900     val project =
   895       Elm.Project("Find_Facts", web_dir, head =
   901       Elm.Project("Find_Facts", web_dir, head =
   896         List(
   902         List(
   900           HTML.style_file("https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons"),
   906           HTML.style_file("https://fonts.googleapis.com/css?family=Roboto:300,400,500|Material+Icons"),
   901           HTML.style_file(
   907           HTML.style_file(
   902             "https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.css"),
   908             "https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.css"),
   903           HTML.script_file(
   909           HTML.script_file(
   904             "https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.js")))
   910             "https://unpkg.com/material-components-web-elm@9.1.0/dist/material-components-web-elm.min.js")))
   905     project.build_html(progress = progress)
   911     project.build_html(output_file, progress = progress)
   906   }
   912   }
   907 
   913 
   908 
   914 
   909   /* find facts */
   915   /* find facts */
   910 
   916 
   915     progress: Progress = new Progress
   921     progress: Progress = new Progress
   916   ): Unit = {
   922   ): Unit = {
   917     val database = options.string("find_facts_database_name")
   923     val database = options.string("find_facts_database_name")
   918     val encode = new Encode(options)
   924     val encode = new Encode(options)
   919 
   925 
   920     val html = build_html(progress = progress)
   926     def rebuild(): String = {
       
   927       build_html(default_web_dir + web_html, progress = progress)
       
   928       File.read(default_web_dir + web_html)
       
   929     }
       
   930 
       
   931     val html = rebuild()
   921 
   932 
   922     val solr = Solr.init(solr_data_dir)
   933     val solr = Solr.init(solr_data_dir)
   923     resolve_indexes(solr)
   934     resolve_indexes(solr)
   924 
   935 
   925     using(solr.open_database(database)) { db =>
   936     using(solr.open_database(database)) { db =>
   931         HTTP.server(port, name = "", services = List(
   942         HTTP.server(port, name = "", services = List(
   932           HTTP.Fonts_Service,
   943           HTTP.Fonts_Service,
   933           HTTP.CSS_Service,
   944           HTTP.CSS_Service,
   934           new HTTP.Service("find_facts") {
   945           new HTTP.Service("find_facts") {
   935             def apply(request: HTTP.Request): Option[HTTP.Response] =
   946             def apply(request: HTTP.Request): Option[HTTP.Response] =
   936               Some(HTTP.Response.html(if (devel) build_html(progress = progress) else html))
   947               Some(HTTP.Response.html(if (devel) rebuild() else html))
   937           },
   948           },
   938           new HTTP.REST_Service("api/block", progress = progress) {
   949           new HTTP.REST_Service("api/block", progress = progress) {
   939             def handle(body: JSON.T): Option[JSON.T] =
   950             def handle(body: JSON.T): Option[JSON.T] =
   940               for {
   951               for {
   941                 request <- Parse.query_block(body)
   952                 request <- Parse.query_block(body)