Skip to content

Commit fa0b9bb

Browse files
committed
Implement new view template for viewing libraries. Add v2 view template files
1 parent 3b61533 commit fa0b9bb

File tree

8 files changed

+717
-20
lines changed

8 files changed

+717
-20
lines changed

Symfony/src/Codebender/LibraryBundle/Controller/ApiViewsController.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Codebender\LibraryBundle\Controller;
44

5+
use Codebender\LibraryBundle\Handler\ApiCommand\GetVersionsCommand;
56
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
67
use Symfony\Component\HttpFoundation\JsonResponse;
78
use Symfony\Component\HttpFoundation\Response;
@@ -31,7 +32,7 @@ public function newLibraryAction()
3132
$form->handleRequest($this->getRequest());
3233

3334
if (!$form->isValid()) {
34-
return $this->render('CodebenderLibraryBundle:Default:newLibForm.html.twig', array(
35+
return $this->render('CodebenderLibraryBundle:Api:newLibForm.html.twig', array(
3536
'authorizationKey' => $authorizationKey,
3637
'form' => $form->createView()
3738
));
@@ -44,7 +45,7 @@ public function newLibraryAction()
4445
$flashBag->add('error', 'Error: ' . $libraryAdded['message']);
4546
$form = $this->createForm(new NewLibraryForm());
4647

47-
return $this->render('CodebenderLibraryBundle:Default:newLibForm.html.twig', [
48+
return $this->render('CodebenderLibraryBundle:Api:newLibForm.html.twig', [
4849
'authorizationKey' => $authorizationKey,
4950
'form' => $form->createView()
5051
]);
@@ -192,35 +193,34 @@ private function fixGitPaths($files, $root, $parentPath)
192193

193194
public function viewLibraryAction()
194195
{
195-
$handler = $this->get('codebender_library.handler');
196-
197196
$request = $this->getRequest();
198197
$library = $request->get('library');
199-
$disabled = $request->get('disabled');
200-
if ($disabled != 1)
201-
$disabled = 0;
202-
else
203-
$disabled = 1;
204-
205-
$response = $handler->getLibraryCode($library, $disabled, true);
198+
$version = $request->get('version');
199+
$disabled = $request->get('disabled') !== 1 ? false : true;
200+
201+
$apiFetchCommand = $this->get('codebender_api.fetch');
202+
$requestData = [
203+
'type'=>'fetch',
204+
'library' => $library,
205+
'disabled' => $disabled,
206+
'version' => $version,
207+
'renderView' => 'true'
208+
];
209+
$response = $apiFetchCommand->execute($requestData);
206210

207211
if ($response['success'] !== true) {
208212
return new JsonResponse($response);
209213
}
210214

211215
$inSync = false;
212216
if (!empty($response['meta'])) {
213-
$inSync = $handler->isLibraryInSyncWithGit(
214-
$response['meta']['gitOwner'],
215-
$response['meta']['gitRepo'],
216-
$response['meta']['gitBranch'],
217-
$response['meta']['gitInRepoPath'],
218-
$response['meta']['gitLastCommit']
219-
);
217+
// TODO: check if the library is synced with Github
218+
$inSync = false;
220219
}
221220

222-
return $this->render('CodebenderLibraryBundle:Default:libraryView.html.twig', array(
221+
return $this->render('CodebenderLibraryBundle:Api:libraryView.html.twig', array(
223222
'library' => $response['library'],
223+
'versions' => $response['versions'],
224224
'files' => $response['files'],
225225
'examples' => $response['examples'],
226226
'meta' => $response['meta'],
@@ -264,7 +264,7 @@ public function searchAction()
264264
if ($json !== null && $json = true) {
265265
return new JsonResponse(['success' => true, 'libs' => $names]);
266266
}
267-
return $this->render('CodebenderLibraryBundle:Default:search.html.twig',
267+
return $this->render('CodebenderLibraryBundle:Api:search.html.twig',
268268
['authorizationKey' => $this->container->getParameter('authorizationKey'), 'libs' => $names]);
269269
}
270270

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
2+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
3+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
4+
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
5+
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
6+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
{% include 'CodebenderLibraryBundle:Api:includes.html.twig' %}
6+
7+
8+
<title></title>
9+
</head>
10+
<body>
11+
<div class="container-fluid">
12+
<div class="span1"></div>
13+
<div class="span10"></div>
14+
<div style="text-align: left;">
15+
{% if meta.name is defined %}
16+
<h2>{{ meta.name }}</h2>
17+
{% else %}
18+
<h2>{{ library }}</h2>
19+
{% endif %}
20+
<h3>(main header: {{ library }}.h)</h3>
21+
{% if meta is not empty %}
22+
{% if meta.verified %}
23+
<span class="label label-success" title="This is a Verified Library."><label class="icon-ok"></label> This is a Verified Library.</span>
24+
{% else %}
25+
<span class="label label-warning" title="Not Verified. Use at your own risk."><label class="icon-warning-sign"></label> Not Verified. Use at your own risk.</span>
26+
{% endif %}
27+
<br/><br/>
28+
{% if meta.active == true %}
29+
<button onclick = "changeLibraryStatus('{{ library }}')" id="statusbutton" class="btn btn-danger" value="isEnabled">Library <strong>enabled</strong> on codebender. Click to disable.</button>
30+
{% else %}
31+
<button onclick = "changeLibraryStatus('{{ library }}')" id="statusbutton" class="btn btn-success" value="isDisabled">Library <strong>disabled</strong> on codebender. Click to enable.</button>
32+
{% endif %}
33+
<br/><br/>
34+
{% if meta.gitOwner and meta.gitRepo and meta.url != '' %}
35+
{% if meta.gitInRepoPath %}
36+
<label>You will find the files in the "<strong>{{ meta.gitInRepoPath }}</strong>" directory of the Github repository </label><br/>
37+
{% endif %}
38+
<a class="btn btn-primary" target="_blank" href = "{{ meta.url }}" title="Github repo hosting the library code">Github Repository</a>
39+
{% elseif meta.url and meta.url != '' %}
40+
<a class="btn btn-primary" target="_blank" href = "{{ meta.url }}" title="Reference page of the library">{{ meta.humanName }} is hosted here</a>
41+
{% endif %}
42+
{% set download_hash = { 'library' : (library), 'authorizationKey': (authorizationKey) } %}
43+
<a id="download" class="btn btn-success" target="_blank"
44+
href="{{ path('codebender_library_download', download_hash) }}">Download from <strong>Eratosthenes</strong></a>
45+
<br/><br/>
46+
{% if meta.gitOwner and meta.gitRepo and meta.gitLastCommit %}
47+
{% if inSyncWithGit == true %}
48+
<span><label class="icon-ok"></label> In sync with <strong>{{ meta.gitBranch }}</strong> branch.</span>
49+
{% else %}
50+
<span><label class="icon-warning-sign"></label> Not in sync with {% if meta.gitBranch %} {{ meta.gitBranch }} {% else %}any{% endif %} branch.</span>
51+
{% endif %}
52+
{% else %}
53+
<span>Not a Github library (might need manual update)</span>
54+
{% endif %}
55+
{% else %}
56+
{% set download_hash = { 'library' : (library), 'authorizationKey': (authorizationKey) } %}
57+
<a id="download" class="btn btn-success" target="_blank"
58+
href="{{ path('codebender_library_download', download_hash) }}">Download from <strong>Eratosthenes</strong></a>
59+
<br/><br/>
60+
<span>This is a <strong>builtin</strong> library</span>
61+
{% endif %}
62+
</div>
63+
{% if meta %}
64+
{% if meta.description %}
65+
<h3>Library Description:</h3>
66+
<div class="well">
67+
<p>{{ meta.description }}</p>
68+
</div>
69+
{% endif %}
70+
{% if meta.libraryNotes %}
71+
<h3>Private notes for codebender staff:</h3>
72+
<div class="well">
73+
<p>{{ meta.libraryNotes }}</p>
74+
</div>
75+
{% endif %}
76+
{% endif %}
77+
{% if versions %}
78+
<h3>Library Files</h3>
79+
<p>Showing {{ versions|length }} version(s).</p>
80+
{% endif %}
81+
<div>
82+
{% if versions %}
83+
{% include 'CodebenderLibraryBundle:Api:template/libraryView_version.html.twig' with {'versions': versions, 'files': files, 'examples': examples} %}
84+
{% else %}
85+
{% include 'CodebenderLibraryBundle:Api:template/libraryView_default.html.twig' with {'files': files, 'examples': examples} %}
86+
{% endif %}
87+
</div>
88+
<div class="span1"></div>
89+
</div>
90+
91+
<script type="text/javascript">
92+
93+
function changeLibraryStatus(library)
94+
{
95+
var route = "{{ path('codebender_library_status_change_v2', {'authorizationKey': authorizationKey, 'library': "LIBRARYNAME"}) }}";
96+
$.post( route.replace("LIBRARYNAME", library) )
97+
.done(function( data ) {
98+
var response = jQuery.parseJSON(data);
99+
if(response.success)
100+
{
101+
$("#statusbutton").toggleClass("btn-success");
102+
$("#statusbutton").toggleClass("btn-danger");
103+
104+
if ($("#statusbutton").text().indexOf('enabled') > 0)
105+
{
106+
$("#statusbutton").html("Library <strong>disabled</strong> on codebender. Click to enable.");
107+
} else if ($("#statusbutton").text().indexOf('disabled') > 0)
108+
{
109+
$("#statusbutton").html("Library <strong>enabled</strong> on codebender. Click to disable.");
110+
}
111+
112+
}
113+
console.log(data);
114+
});
115+
}
116+
117+
</script>
118+
119+
</body>
120+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<head xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
2+
{% include 'CodebenderLibraryBundle:Api:includes.html.twig' %}
3+
<script src="{{ asset('js/jstree.min.js') }}"></script>
4+
<script src={{ asset("js/zip.js") }}></script>
5+
{% include 'CodebenderLibraryBundle:Api:page-logic.html.twig' %}
6+
<link rel="stylesheet" type="text/css" href="{{ asset('css/newlibform.css') }}">
7+
<link rel="stylesheet" type="text/css" href="{{ asset('css/jstree/themes/default/style.min.css') }}" />
8+
</head>
9+
10+
<body>
11+
12+
<div class="container-fluid">
13+
<div class="row-fluid">
14+
<div class="span1"></div>
15+
<div class="span10">
16+
<h2 class="title" style="text-align: center;">Let's add some libraries!</h2>
17+
<br/>
18+
<h3>
19+
{% for flashMessage in app.session.flashbag.get('error') %}
20+
<i>{{ flashMessage }}</i>
21+
{% endfor %}
22+
</h3>
23+
<h3 id = "newLibMessage"></h3>
24+
25+
<div class="row-fluid">
26+
<div id="steps" class="span12 clearfix">
27+
<ol>
28+
<li><a class="active step1" title="Select between Github or zip" onclick="selectStep(1)">1</a></li>
29+
<li><a class="step2" title="Select directory (only applies to Github libraries)" onclick="selectStep(2)">2</a></li>
30+
<li><a class="step3" title="Add library (submit the form)" onclick="selectStep(3)">3</a></li>
31+
</ol>
32+
</div>
33+
</div>
34+
<div class="row-fluid">
35+
<div class="span6">
36+
<div id="step1" class="box sourcediv">
37+
<div id="gitHubDiv">
38+
<div class="row-fluid">
39+
<div class="span12" style="text-align: center;">
40+
<h3 class="labelcontent clearfix"><span><i class="fa fa-github fa-2x"></i> Use a Github Url</span></h3>
41+
<br/>
42+
<input type="text" id="githubUrl" class="input-lg" autocomplete="off" placeholder="Enter Github Url"/>
43+
<br/>
44+
<button id="fetchBranchesBtn" class="btn btn-info">Get the branches of the repo</button>
45+
</div>
46+
</div>
47+
<br/>
48+
<div class="row-fluid">
49+
<div class="span12" style="text-align: center;">
50+
<h3 id="gitBranchDiv" class="labelcontent clearfix"><span><i class="fa fa-code-fork fa-2x"></i> Select a branch</span></h3>
51+
<br/>
52+
<select id="gitBranches"></select>
53+
<br/>
54+
<button id="fetchFilesBtn" class="btn btn-info">Get the files of the repo</button>
55+
</div>
56+
</div>
57+
</div>
58+
<h3 id='orDiv' class="labelcontent clearfix">- or -</h3>
59+
<div id="zipDiv" style="text-align: center;">
60+
<h3 class="labelcontent clearfix"><span><i class="fa fa-upload fa-2x"></i> Upload a zip file</span></h3>
61+
<br/>
62+
<button id="takeMeThereButton" class="btn btn-info">Take me there</button>
63+
</div>
64+
</div>
65+
<div id="step2" style="overflow: scroll">
66+
<div id="jstreeDiv"></div>
67+
</div>
68+
</div>
69+
<div class="span6">
70+
<div id="step3" class="box metadiv">
71+
<div id="verify">
72+
<h5 id="githubChangeInfo" class="labelcontent clearfix">
73+
Repository owner: <span id="repoInfoOwner"></span><br/>
74+
Repository name: <span id="repoInfoRepoName"></span><br/>
75+
Selected branch: <span id="repoInfoBranch"></span><br/>
76+
Selected folder: <span id="repoInfoFolder"></span><br/>
77+
</h5>
78+
<a href="javascript:void(0);" class="btn btn-success" id="yes">All good</a>
79+
</div>
80+
<div id="form">
81+
{{ form_start(form) }}
82+
{{ form_errors(form) }}
83+
{{ form_widget(form.Zip) }}
84+
<h3 class="labelcontent clearfix"><span><i class="fa fa-caret-right"></i> Human Name:</span> {{ form_widget(form.HumanName) }}</h3>
85+
<h3 class="labelcontent clearfix"><span><i class="fa fa-caret-right"></i> Machine Name:</span> <select id="machineNames">Machine Names</select></h3>
86+
<h3 class="labelcontent clearfix"><span><i class="fa fa-caret-right"></i> Description:</span> {{ form_widget(form.Description) }}</h3>
87+
<h3 id="urlDiv" class="labelcontent"><span><i class="fa fa-caret-right"></i> Info Url:</span> {{ form_widget(form.Url) }}</h3>
88+
<h3 id="sourceUrlDiv" class="labelcontent"><span><i class="fa fa-caret-right"></i> Source Url:</span> {{ form_widget(form.SourceUrl) }}</h3>
89+
<h3 id="sourceUrlDiv" class="labelcontent"><span><i class="fa fa-caret-right"></i> Notes for the library:</span><br/> {{ form_widget(form.Notes) }}</h3>
90+
{{ form_end(form) }}
91+
</div>
92+
</div>
93+
</div>
94+
</div>
95+
<div class="span1"></div>
96+
</div>
97+
</div>
98+
</div>
99+
100+
</body>
101+
102+
103+

0 commit comments

Comments
 (0)