Skip to content

Commit 80f657a

Browse files
committed
Initial support for web base YAML editor.
1 parent 0fa16bd commit 80f657a

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "appclib/ace"]
2+
path = appclib/ace
3+
url = https://github.com/ajaxorg/ace-builds.git

appclib/ace

Submodule ace added at cf53674

application/yaml_editor.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
class yaml_editor extends x_table2 {
3+
function main() {
4+
echo( '
5+
<style type="text/css">
6+
#yamleditor {
7+
width:100%;
8+
border: 1px solid #DDD;
9+
border-radius: 4px;
10+
border-bottom-right-radius: 0px;
11+
}
12+
</style>
13+
' );
14+
echo( '<script type="text/javascript" src="/appclib/ace/src-min-noconflict/ace.js" data-ace-base="/appclib/ace/src-min-noconflict" charset="utf-8"></script>');
15+
16+
17+
if ( isset( $_REQUEST['gp_file'] ) && isset( $_REQUEST['gp_app'] ) ) {
18+
$application=gp('gp_app');
19+
$appInfo = $this->getAppInfo($application);
20+
$parts = explode(DIRECTORY_SEPARATOR, $GLOBALS['AG']['dirs']['root']);
21+
array_pop($parts);
22+
array_pop($parts);
23+
$file = join(DIRECTORY_SEPARATOR, $parts) .DIRECTORY_SEPARATOR .trim($application) .DIRECTORY_SEPARATOR .'application' .DIRECTORY_SEPARATOR .gp('gp_file');
24+
$contents = file_get_contents($file);
25+
echo( '
26+
<div class="btn-toolbar" style="clear:both;padding-bottom:10px;">
27+
<div class="btn-group pull-left">
28+
<span style="font-size:20pt;"><strong>Application: </strong>' .$application .' &nbsp;&nbsp;<strong>File: </strong>' .gp('gp_file') .(!empty( $appInfo['vcs_url'] ) ? ' <strong>(READ ONLY)</strong>' : '' ) .'</span>
29+
</div>
30+
');
31+
if ( empty( $appInfo['vcs_url'] ) ) {
32+
echo( '<div class="btn-group pull-right">
33+
<a class="btn btn-primary" href="#"><i class="icon-ok icon-white"></i> Save</a>
34+
</div>
35+
' );
36+
}
37+
echo( '
38+
&nbsp;
39+
</div>
40+
');
41+
echo( '<div id="yamleditor">' .$contents .'</div>');
42+
echo( '
43+
<div class="btn-toolbar" style="clear:both;padding-bottom:10px;">
44+
');
45+
if ( empty( $appInfo['vcs_url'] ) ) {
46+
echo( '<div class="btn-group pull-right">
47+
<a class="btn btn-primary" href="#"><i class="icon-ok icon-white"></i> Save</a>
48+
</div>
49+
' );
50+
}
51+
echo( '
52+
&nbsp;
53+
</div>
54+
');
55+
JqDocReady('
56+
editor = ace.edit(\'yamleditor\');
57+
editor.setTheme(\'ace/theme/github\');
58+
editor.setFontSize(14);
59+
editor.setHighlightSelectedWord(true);
60+
editor.setShowInvisibles(true);
61+
editor.setShowPrintMargin(false);
62+
editor.setAnimatedScroll(true);
63+
editor.setBehavioursEnabled(true);
64+
editor.setDisplayIndentGuides(true);
65+
editor.getSession().setMode(\'ace/mode/yaml\');
66+
' .(!empty( $appInfo['vcs_url'] ) ? 'editor.setReadOnly(true);' : '' ) .'
67+
68+
heightUpdateFunction = function() {
69+
var newHeight = $(window).height() - ($(\'.navbar\').height() + 145);
70+
71+
$(\'#yamleditor\').height(newHeight.toString() + "px");
72+
73+
// This call is required for the editor to fix all of
74+
// its inner structure for adapting to a change in size
75+
editor.resize();
76+
};
77+
width = \'\';
78+
height = \'\';
79+
// Set initial size to match initial content
80+
heightUpdateFunction();
81+
setInterval(function () {
82+
if ((width != $(window).width()) || (height != $(window).height())) {
83+
width = $(window).width();
84+
height = $(window).height();
85+
heightUpdateFunction();
86+
}
87+
}, 300);
88+
');
89+
} else {
90+
$this->showFileChooser();
91+
}
92+
}
93+
94+
function getAppInfo($application) {
95+
$query = "SELECT * FROM " .ddView('applications') ." WHERE application='" .$application ."'";
96+
$data = SQL_OneRow( $query );
97+
return $data;
98+
}
99+
100+
function showFileChooser() {
101+
$query = "SELECT * FROM " .ddView('applications') ." ORDER BY application";
102+
$applications = SQL_AllRows( $query );
103+
foreach( $applications as $application ) {
104+
echo( '<ul><strong>' .$application['application'] .'</strong>');
105+
$yaml_files = $this->getYAMLFiles($application['application']);
106+
foreach( $yaml_files as $yaml_file) {
107+
echo( '<li><a href="/index.php?gp_page=yaml_editor&gp_app=' .trim($application['application']) .'&gp_file=' .$yaml_file .'">' .$yaml_file .'</a></li>');
108+
}
109+
echo( '</ul>' );
110+
}
111+
}
112+
113+
function getYAMLFiles($application) {
114+
$files = array();
115+
$parts = explode(DIRECTORY_SEPARATOR, $GLOBALS['AG']['dirs']['root']);
116+
array_pop($parts);
117+
array_pop($parts);
118+
$path = join(DIRECTORY_SEPARATOR, $parts) .DIRECTORY_SEPARATOR .trim($application) .DIRECTORY_SEPARATOR .'application';
119+
if ($handle = opendir($path)) {
120+
while( false !== ($entry = readdir($handle))) {
121+
if (!is_dir($entry)) {
122+
if (stripos($entry, '.yaml') !== false) {
123+
array_push($files, $entry);
124+
}
125+
}
126+
}
127+
}
128+
return $files;
129+
}
130+
}

0 commit comments

Comments
 (0)