Commit 00652de4 authored by Peter Achten's avatar Peter Achten

restructured svg library and editor

parent 46bf9036
definition module Administration.Tasks
import iTasks
import CivilAffairs.UoD
/** currentCitizen:
this task returns the available citizen information of the current user.
*/
currentCitizen :: Task Citizen
/** batchProcessing:
this task gathers all registered collections that have not yet been paid and pays them.
As a result, these payed collections are removed from collectionPayments and added to
collectionsProcessed.
*/
batchProcessing :: Task ()
/** viewSelectedCitizen:
this task provides an overview of all citizens and allows you to view all registered.
information of a selected citizen.
*/
viewSelectedCitizen :: Task ()
/** viewAddressOfCurrentUser:
this task shows the address of the current user, if the user has a home address.
*/
viewAddressOfCurrentUser :: Task ()
/** showCitizenInformationOfCurrentUser:
this task shows all registered information of a registered user.
*/
showCitizenInformationOfCurrentUser :: Task ()
/** convertExampleData:
this task reads the example files from 'ExampleData' and creates / fills the appropriate
SDS's.
*/
convertExampleData :: Task ()
implementation module Administration.Tasks
import iTasks
import Text
import Text.HTML
import Data.Either
import Task.Extensions
import System.Directory, System.FilePath
import Cadastre.SDS, ChamberOfCommerce.SDS, Compensation.SDS, CivilAffairs.SDS
import StdArray, StdFile
batchProcessing :: Task ()
batchProcessing
= pay
pay :: Task ()
pay
= get currentDate
>>- \today -> get collectionPayments
>>- \payments ->
let pay_now = filter (\collection=:{Collection | date} -> date <= today) payments
pay_later = filter (\collection=:{Collection | date} -> date > today) payments
in set pay_later collectionPayments
>>| addToStore pay_now collectionsProcessed
>>| viewInformation "Payments performed on:" [] today
>>| pay
viewSelectedCitizen :: Task ()
viewSelectedCitizen
= (enterChoiceWithShared () [ChooseFromGrid (\{Citizen|name,ssn} -> "" <+++ name <+++ " (" <+++ ssn <+++ ")") ] citizens
>&> withSelection (viewInformation () [] "Select a citizen")
(\citizen -> viewCitizenInformation citizen.Citizen.ssn defaultValue) )<<@ ApplyLayout (arrangeWithSideBar 0 LeftSide 200 True)
viewCitizenInformation :: SSN Date -> Task ()
viewCitizenInformation ssn date
= getCitizen ssn
>>- \mbCit -> if (isNothing mbCit) (return ())
( return (fromJust mbCit)
>>- \cit=:{Citizen|ssn} ->
( viewInformation "Overview data:" [] ())
-|| ( viewInformation (Title "Address information") [] cit
-&&-
enterChoiceWithShared (Title "Real estate") [ChooseFromGrid id] (currentRealEstate cit)
-&&-
enterChoiceWithShared (Title "Decisions") [ChooseFromGrid id] (currentDecisions ssn (\_ -> True) date)
-&&-
enterChoiceWithShared (Title "You will receive...") [ChooseFromGrid id] (currentPayments ssn date)
-&&-
enterChoiceWithShared (Title "You need to pay... ") [ChooseFromGrid id] (currentClaims ssn date)
-&&-
enterChoiceWithShared (Title "Received / Payed") [ChooseFromGrid id] (currentProcessed ssn date)
))
viewAddressOfCurrentUser :: Task ()
viewAddressOfCurrentUser
= currentCitizen
>>- \citizen -> viewInformation "My data:" [] citizen
-||
viewInformation () [] (if (isNothing citizen.Citizen.homeAddress)
(Text "Unknown home address")
(showAddress (fromJust citizen.Citizen.homeAddress).Address.postcode (fromJust citizen.Citizen.homeAddress).Address.houseNumber))
@! ()
where
showAddress postcode houseNumber
= ATag [HrefAttr ("https://bagviewer.kadaster.nl/lvbag/bag-viewer/#?searchQuery=" +++ postcode +++ " " +++ toString houseNumber), TargetAttr "_inline"] [Text "Show address on map"]
getCitizen :: SSN -> Task (Maybe Citizen)
getCitizen ssn
= get citizens
>>- \cits -> return (citizenFromSSN ssn cits)
// current User logged in
// authenticated users always have a SSN
currentSSN :: Task SSN
currentSSN
= get currentUser
>>- \(AuthenticatedUser userId roles title) -> return (hd [ssn \\ role <- roles , ("ssn",ssn) <- [(role%(0,2),role%(3,11))]])
currentCitizen :: Task Citizen
currentCitizen
= currentSSN
>>- \ssn -> getCitizen ssn
>>- \citizen -> return (fromJust citizen)
showCitizenInformationOfCurrentUser :: Task ()
showCitizenInformationOfCurrentUser
= currentSSN
>>- \ssn -> viewCitizenInformation ssn defaultValue
>>| return ()
examplefilepath :: !FilePath !String -> FilePath
examplefilepath dir filename = dir <+++ pathSeparator <+++ "ExampleData" <+++ pathSeparator <+++ filename
convertExampleData :: Task ()
convertExampleData
= accWorldError getCurrentDirectory (\(errorcode,errormsg) -> "convert task failed to access current directory (errorcode: " <+++ errorcode <+++ ", errormsg: " <+++ errormsg <+++ ".\n")
>>- \curDir -> readLinesFromFile (examplefilepath curDir "roofing_companies.txt")
>>- \lines -> set [{ cocNo = no
, cocName = name
, type = ["solar panel company"]
} \\ line <- lines,
[no,name:_] <- [split "\t" line]
] companies
>>= \roofers -> viewInformation "roofing companies:" [] roofers
>>| readLinesFromFile (examplefilepath curDir "adresses.txt")
>>- \lines -> set [{ Citizen
| ssn = ssn
, name = {Name | forename = fore, surname = sur}
, homeAddress = if (postcode == "AU") Nothing
(Just {Address | postcode = postcode, houseNumber = toInt no})
}
\\ line <- lines,
[ssn,fore,sur,postcode,no:_] <- [split "\t" line]
] citizens
>>= \cvs -> viewInformation "citizens:" [] cvs
>>| readLinesFromFile (examplefilepath curDir "real_estate_owners.txt")
>>- \lines -> set (foldl add_real_estate_owner [] lines) realEstateOwners
>>= \owners -> viewInformation "real estate owners:" [] owners
>>| set (foldl add_cadastre_real_estate [] owners) cadastreRealEstate
>>= \cadastre -> viewInformation "cadastre:" [] cadastre
>>| readLinesFromFile (examplefilepath curDir "officers.txt")
>>- \officers -> importDemoUsersFlow
>>- \demoAccounts ->
set ([{UserAccount | credentials = { username = Username "root", password = Password "root"}
, title = Just "root", roles = ["admin","programmer","god"]
}] ++
[{UserAccount | demo & roles = ["admin"]} \\ demo <- demoAccounts] ++
[{UserAccount | credentials = { username = Username officer, password = Password officer}
, title = Just officer, roles = ["officer"]
}
\\ officer <- map rtrim officers] ++
[{UserAccount | credentials = { username = Username roofer.cocNo, password = Password roofer.cocNo}
, title = Just roofer.cocName, roles = ["roofing company"]
}
\\ roofer <- roofers] ++
[{UserAccount | credentials = { username = Username cv.Citizen.ssn, password = Password cv.Citizen.ssn}
, title = Just (cv.Citizen.name.forename +++ " " +++ cv.Citizen.name.surname), roles = ["citizen","ssn"+++ toString cv.Citizen.ssn]
}
\\ cv <- cvs]
) userAccounts
>>= viewInformation "accounts" []
>>| viewInformation "Done!" [] ()
where
add_real_estate_owner :: [RealEstateOwner] String -> [RealEstateOwner]
add_real_estate_owner data line_from_real_estate_owners
= case span (\{RealEstateOwner | ownerID} -> ownerID <> id) data of
(before, [owner : after]) = before ++ [{RealEstateOwner | owner & addresses = owner.RealEstateOwner.addresses ++ [address]} : after]
(all_of_them, none) = all_of_them ++ [{RealEstateOwner | ownerID = id, addresses = [address]}]
where
[postcode,no,ssn_or_coc:_] = split "\t" line_from_real_estate_owners
address = {Address | postcode = postcode, houseNumber = toInt no}
id = if (size ssn_or_coc == 8) (Right ssn_or_coc) (Left ssn_or_coc)
add_cadastre_real_estate :: [CadastreRealEstate] RealEstateOwner -> [CadastreRealEstate]
add_cadastre_real_estate data {RealEstateOwner | ownerID,addresses}
= foldl (add_real_estate ownerID) data addresses
where
add_real_estate :: Owner [CadastreRealEstate] Address -> [CadastreRealEstate]
add_real_estate new_owner data new_address
= case span (\{CadastreRealEstate | address} = address <> new_address) data of
(before, [cre : after]) = before ++ [{CadastreRealEstate | cre & subOwners = cre.CadastreRealEstate.subOwners ++ [new_owner]} : after]
(all_of_them, none) = all_of_them ++ [{CadastreRealEstate | address = new_address, mainOwner = new_owner, subOwners = []}]
// copied from directoryBrowsing:
readLinesFromFile :: !String -> Task [String]
readLinesFromFile path = accWorldError (read path) id
where
read path world
# (ok,file,world) = fopen path FReadData world
| not ok = (Error ("Cannot find file: " +++ path), world)
# (res,file) = readAllLines file []
# (ok,world) = fclose file world
| not ok = (Error ("Cannot close file: " +++ path), world)
= (Ok res, world)
readAllLines file accu
# (line,file) = freadline file
| line == "" = (reverse accu,file)
= readAllLines file [line:accu]
definition module Cadastre.SDS
import Cadastre.UoD
/** cadastreRealEstate:
this shared data source keeps track of the registered owners per address.
*/
cadastreRealEstate :: Shared [CadastreRealEstate]
implementation module Cadastre.SDS
import Cadastre.UoD
cadastreRealEstate :: Shared [CadastreRealEstate]
cadastreRealEstate = sharedStore "cadastreRealEstate" []
definition module Cadastre.Tasks
import iTasks
/** editCadastreRealEstate:
this task allows you to view and alter the currently registered information about the
owners of real estate per address.
*/
editCadastreRealEstate :: Task ()
implementation module Cadastre.Tasks
import Task.Extensions
import Cadastre.SDS
editCadastreRealEstate :: Task ()
editCadastreRealEstate = editStore "List of cadastre real estate" cadastreRealEstate
definition module Cadastre.UoD
import CivilAffairs.UoD, ChamberOfCommerce.UoD
/** CadastreRealEstate:
keep track of all owners of the real estate registered at a given address.
*/
:: CadastreRealEstate
= { address :: Address /** the address (serves as key) of the registered real estate */
, mainOwner :: Owner /** the main owner of the real estate */
, subOwners :: [Owner] /** possibly additional owners of the real estate */
}
/** Owner:
the registered owner of a real estate is either a citizen (identified via *SSN*) or a company
(identified via *COCN*).
*/
:: Owner
:== Either SSN COCN
derive class iTask CadastreRealEstate
/** == a b:
yields True only if @a.address == @b.address.
*/
instance == CadastreRealEstate
/** < a b:
yields True only if @a.address < @b.address.
*/
instance < CadastreRealEstate
/** == (Left a) (Left b):
yields @a == @b.
== (Right a) (Right b):
yields @a == @b.
== _ _:
yields False.
*/
instance == (Either a b) | Eq a & Eq b
/** < (Left a) (Left b):
yields @a < @b.
< (Right a) (right b):
yields @a < @b.
< (Left _) _:
yields True.
< _ _:
yields False.
*/
instance < (Either a b) | Ord a & Ord b
implementation module Cadastre.UoD
import CivilAffairs.UoD, ChamberOfCommerce.UoD
from Data.Either import :: Either(..)
derive class iTask CadastreRealEstate
instance == CadastreRealEstate where == a1 a2 = a1.CadastreRealEstate.address == a2.CadastreRealEstate.address
instance < CadastreRealEstate where < a1 a2 = a1.CadastreRealEstate.address < a2.CadastreRealEstate.address
instance == (Either a b) | Eq a & Eq b where == (Left a) (Left b) = a == b
== (Right a) (Right b) = a == b
== _ _ = False
instance < (Either a b) | Ord a & Ord b where < (Left a) (Left b) = a < b
< (Left _) _ = True
< (Right a) (Right b) = a < b
< _ _ = False
definition module ChamberOfCommerce.SDS
import ChamberOfCommerce.UoD
/** companies:
this shared data source keeps track of all registered companies.
*/
companies :: Shared [Company]
/** companiesOfType t:
this shared data source is the subset of *companies* of type @t.
*/
companiesOfType :: CompanyType -> Shared [Company]
implementation module ChamberOfCommerce.SDS
import ChamberOfCommerce.UoD
companies :: Shared [Company]
companies = sharedStore "companies" []
companiesOfType :: CompanyType -> Shared [Company]
companiesOfType type = mapRead (filter (companyHasType type)) companies
definition module ChamberOfCommerce.Tasks
import iTasks
/** editCompanies:
this task allows you to view and alter the currently registered companies.
*/
editCompanies :: Task ()
implementation module ChamberOfCommerce.Tasks
import Task.Extensions
import ChamberOfCommerce.SDS
editCompanies :: Task ()
editCompanies = editStore "List of companies" companies
definition module ChamberOfCommerce.UoD
import iTasks
/** Company:
keep track of company information in the Chamber of Commerce Register.
*/
:: Company
= { cocNo :: COCN /** the unique Chamber of Commerce number of the company (serves as key) */
, cocName :: String /** the official company name */
, type :: [CompanyType] /** the type of the company */
}
/** COCN:
the Chamber of Commerce number, uniquely distributed to all registered companies
*/
:: COCN
:== String
/** CompanyType:
the type of the company (for simplicity, a single string that serves as key in its entirety)
*/
:: CompanyType
:== String
derive class iTask Company
/** companyHasType type company:
returns True only if one of the elements of @company.type is @type.
*/
companyHasType :: CompanyType Company -> Bool
/** == c1 c2:
yields True only if @c1.cocNo == @c2.cocNo
*/
instance == Company
/** < c1 c2:
yields True only if @c1.cocNo < @c2.cocNo
*/
instance < Company
implementation module ChamberOfCommerce.UoD
import iTasks
derive class iTask Company
companyHasType :: CompanyType Company -> Bool
companyHasType ct {Company | type} = isMember ct type
instance == Company where == a1 a2 = a1.Company.cocNo == a2.Company.cocNo
instance < Company where < a1 a2 = a1.Company.cocNo < a2.Company.cocNo
definition module CivilAffairs.SDS
import CivilAffairs.UoD
/** citizens:
this shared data source keeps track of all registered citizens.
*/
citizens :: Shared [Citizen]
implementation module CivilAffairs.SDS
import CivilAffairs.UoD
citizens :: Shared [Citizen]
citizens = sharedStore "citizens" []
definition module CivilAffairs.Tasks
import CivilAffairs.SDS
/** editCitizens:
this task allows you to view and alter the information of all currently registered citizens.
*/
editCitizens :: Task ()
implementation module CivilAffairs.Tasks
import Task.Extensions
import CivilAffairs.SDS
editCitizens :: Task ()
editCitizens = editStore "List of citizens" citizens
definition module CivilAffairs.UoD
import iTasks
import iTasks.Extensions.Document //import :: Document(..), :: DocumentId
/** Citizen:
keeps track of all citizen information.
*/
:: Citizen
= { ssn :: SSN /** the social security number */
, name :: Name /** the name */
, homeAddress :: Maybe Address /** the home address, if any */
}
/** SSN:
a unique identification number for each citizen
*/
:: SSN
:== String
/** NameHomeAddress:
keeps track of the name and home address of a citizen.
*/
:: NameHomeAddress
= { name :: Name /** the name */
, homeAddress :: Address /** the home address */
}
/** Name:
keeps track of the name of a citizen.
*/
:: Name
= { forename :: String /** forename */
, surname :: String /** surname */
}
/** Address:
keeps track of an address, using postcode and house number combination.
*/
:: Address
= { postcode :: Postcode /** postcode */
, houseNumber :: Int /** house number */
}
/** Postcode:
in the Netherlands this string is formatted as a sequence of four digits (0..9) and two
alphabetic characters (A..Z).
*/
:: Postcode
:== String
/** Amount:
for simplicity, the amount in euros
*/
:: Amount
:== Int
/** Photo:
for simplicity, a photo is identified via an iTask *Document*
*/
:: Photo
:== Document
/** citizenFromSSN ssn all_citizens = Just citizen:
@citizen is a member of @all_citizens and @citizen.ssn == @ssn.
citizenFromSSN ssn all_citizens = Nothing:
@all_citizens does not contain a citizen c for which c.ssn == @ssn.
*/
citizenFromSSN :: SSN [Citizen] -> Maybe Citizen
/** nameHomeAddressFromCitizen citizen=:{home_address=Just address} = nha:
@nha contains the @citizen.name and @address.