Skip to content

Commit

Permalink
add form for creating a new project
Browse files Browse the repository at this point in the history
  • Loading branch information
jmague committed Oct 27, 2015
1 parent 8684d65 commit 29ca59b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 41 deletions.
48 changes: 38 additions & 10 deletions _restxq/synopsx.xqm
Expand Up @@ -115,14 +115,42 @@ declare
%rest:query-param("project", "{$project}")
%updating
function config($project) {
db:create-backup('synopsx'),
(: supprimer tout attribut défault préexistant :)
delete node db:open('synopsx', 'config.xml')//@default,
(: si le projet existe, lui ajouter l'attribut default=true :)
if (db:open('synopsx', 'config.xml')//dbName/text() = $project) then insert node (attribute { 'default' } { 'true' }) into db:open('synopsx', 'config.xml')//project[dbName/text()=$project]
else insert node <project default="true">
<resourceName>{$project}</resourceName>
<dbName>{$project}</dbName>
</project> into db:open('synopsx', 'config.xml')//projects,
db:output(web:redirect("/synopsx/config"))
db:create-backup('synopsx'),
delete node db:open('synopsx', 'config.xml')//@default, (: supprimer tout attribut défault préexistant :)
insert node (attribute { 'default' } { 'true' }) into db:open('synopsx', 'config.xml')//project[resourceName/text()=$project],
db:output(web:redirect("/synopsx/config"))
};


declare
%rest:GET
%restxq:path('/synopsx/create-project')
%output:method('html')
%output:html-version('5.0')
function create_project() as element(html) {
let $queryParams := map {

}
let $outputParams :=map {
'lang' : 'fr',
'layout' : 'create-project.xhtml'
}
return synopsx.models.synopsx:htmlDisplay($queryParams, $outputParams)
};

declare
%rest:POST
%restxq:path('/synopsx/create-project')
%output:method('html')
%rest:query-param("project", "{$project}")
%updating
function create_project($project) {
db:create($project, (), (), map { 'chop': fn:true(), 'textindex': fn:true(),'attrindex': fn:true() }),
insert node
<project>
<resourceName>{$project}</resourceName>
<dbName>{$project}</dbName>
</project>
into db:open('synopsx', 'config.xml')//projects,
db:output(web:redirect("/synopsx/config"))
};
19 changes: 10 additions & 9 deletions models/synopsx.xqm
Expand Up @@ -41,24 +41,25 @@ declare default function namespace "synopsx.models.synopsx";
: @rmq for testing with new htmlWrapping
:)
declare function getProjectsList($queryParams as map(*)) as map(*) {
let $databases := db:list()
let $projects := db:open('synopsx', 'config.xml')//project
let $meta := map{
'title' : 'Liste des bases de données',
'count' : fn:string(fn:count($databases)),
'title' : 'Liste des projets',
'count' : fn:string(fn:count($projects)),
'defaultProject' : getDefaultProject()
}
let $content := for $database in $databases return
getSynopsxStatus($queryParams, $database)
let $content := for $project in $projects return
getSynopsxStatus($project)
return map{
'meta' : $meta,
'content' : $content
}
};

declare function getSynopsxStatus($queryParams as map(*), $database) as map(*) {
let $isProject := fn:exists(synopsx.models.synopsx:getDb($queryParams)//project[/dbName=$queryParams('database')])
let $isDefault := $isProject and fn:exists(synopsx.models.synopsx:getDb($queryParams)//project[@default="true"])
return map {'database':$database,'isProject':fn:string($isProject), 'isDefault':fn:string($isDefault)}
declare function getSynopsxStatus($project) as map(*) {
let $isDefault := if (fn:exists($project/@default) and $project/@default=fn:true())
then "checked"
else ""
return fn:trace(map {'project':fn:string($project/resourceName/text()), 'isDefault':$isDefault})
};

(:~
Expand Down
28 changes: 10 additions & 18 deletions templates/config.xhtml
Expand Up @@ -30,31 +30,23 @@
<h1>{title}</h1>
<hr/>
<section>
<h1><span>{count}</span> &#160; bases</h1>
<p>Projet par défaut : <span>{defaultProject}</span></p>
<p>Séléctionnez la base de données du projet par défault</p>
<p>Si votre base n'existe pas encore, créez-la &#160;<a href="/dba/create-db" target="_blank">dans le module d'administration</a> &#160; puis &#160; <a href="/synopsx/config">cliquez ici</a></p>
<form action="/synopsx/config" method="POST">
<p>Default project : <span>{defaultProject}</span></p>
<p>Change default project</p>
<form action="/synopsx/config" method="POST" class="form-inline">
<select name="project">
{content}
<input type="submit" value="OK"/>
</select>
<input type="submit" value="OK" style="display:inline;"/>
</form>



</section>
<a href="/synopsx/create-project"> Create new project </a>
</section>
</div>
</div>

<!-- <div id="content">
<section id="primary" class="home">
<section>
<h3>{title}</h3>
{content}
</section>
</section>
</div> -->
<footer data-url="inc_footer"/>
<script type="text/javascript">
// synopsx's composition
Expand Down
62 changes: 62 additions & 0 deletions templates/create-project.xhtml
@@ -0,0 +1,62 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta charset="utf-8" />
<title>{title}</title>
<meta name="description" content="{description}" />
<meta name="author" content="{author}" />
<meta name="keywords" content="{subject}" />
<link rel="copyright" href="{copyright}"/>


<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="/synopsx/files/css/main.css" rel="stylesheet" />

<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="/synopsx/files/js/synopsx.js"></script>
<!-- ajouter js pour lt IE 9 -->
</head>
<body>

<header data-url="inc_header"/>

<div class="container">
<div class="row">
<hr/>
<hr/>
<section>
<h1>New project</h1>
<hr/>
<section>
<form action="/synopsx/create-project" method="POST">
<input type="text" name="project"/>
<input type="submit" value="OK"/>
</form>
</section>
</section>
</div>
</div>

<!-- <div id="content">
<section id="primary" class="home">
<section>
<h3>{title}</h3>
{content}
</section>
</section>
</div> -->
<footer data-url="inc_footer"/>
<script type="text/javascript">
// synopsx's composition
$(document).ready(function(){
init();
});
</script>
</body>
</html>
5 changes: 1 addition & 4 deletions templates/inc_configItem.xhtml
Expand Up @@ -2,7 +2,4 @@
TODO : revenir à un système d'attributs @data, par exemple @data-content et @data-attribute pour une écriture plus propre
réécrire la fontion synopsx.mappings.htmlWrapping:simplePattern en fonction de ce changement
-->
<span>
<label>{database}</label>
<input type="radio" name="project" value="{database}" checked="{isDefault}"/>
</span>
<option value="{project}">{project}</option>

0 comments on commit 29ca59b

Please sign in to comment.