Wall example - taking inputs from a file
In the tutorial Getting started with GendL we developed an example application to build a model of a building. In that application, all inputs were provided as input-slots with default values. We then extended that in the tutorial Reading from and Writing to Files to take inputs from a file and deliver the output as a file. In this topic, we'll use the building application and extend it to include a web based front end to upload a file via a form.
The basic design concept is to have a web page as a top level object, which provides a form to upload an input file. The building application based on file inputs will be a child object of the file upload form, and once the file has been uploaded it will be passed to te building application as an inout. An output file will be written and a link to that file displayed on the file upload page
The first step is to create a file upload form and incorporate the building application as a child object
(in-package :gwl-user)(define-object building-application-file (base-ajax-sheet):computed-slots((uploaded-path "" :settable)(main-sheet-body (with-cl-who-string ()(str (the development-links))(when (= (length (the uploaded-path)) 0)(htm (with-html-form (:multipart? t :cl-who? t)(:table (:tr (:td(:input :type "file" :name :uploaded-path)))(:tr (:td (:input :type "submit" :name "upload" :value "Upload")))))))))):objects((building :type 'building:input-filename (when (> (length (the uploaded-path)) 1) (the uploaded-path)))
Not that for expediency, the building object has been moved to the gwl-user package for this example
To generate the output, we need to run the write-bom-file! function in the bulding object, following which we need to publish that file and provide a link to it on the web page. As we will demand the url of the published file, we can use side effecting to run the file generation and publishing, rather than running them as a function. To do this we use a computed-slot output-url and the body form of the let macro to evaulate the file write and publish functions sequentially. We've also defined the output filename, such that it will be in the same directory as the uploaded file, but with a different name