31 abstract public function loadView($viewName, $pData = NULL, $asString =
false);
33 abstract public function git();
35 abstract protected function showConfMessage($content, $type, $itle,$url, $responseElement, $data, $attributes = NULL): HtmlMessage;
37 abstract protected function showSimpleMessage($content, $type, $title=null,$icon =
"info", $timeout = NULL, $staticName = null): HtmlMessage;
41 echo $this->jquery->compile ( $this->view );
47 protected function _getRepo($getfiles =
true) {
57 $gitignoreFile=$appDir. DS .
".gitignore";
58 if(!file_exists($gitignoreFile)){
62 }
catch(GitException $ge){
63 echo $this->
showSimpleMessage ( $ge->getMessage(),
"negative",
"Push",
"upload", null,
"init-message" );
64 echo $this->jquery->compile ( $this->view );
71 $this->jquery->execOn (
"click",
"#validate-btn",
'$("#frmGitSettings").form("submit");' );
72 $this->jquery->execOn (
"click",
"#cancel-btn",
'$("#frm").html("");' );
73 $this->jquery->renderView ( $this->
_getAdminFiles ()->getViewGitSettings () );
77 $gitRepo = $this->
_getRepo (
false );
78 $activeRemoteUrl = $gitRepo->getRemoteUrl ();
81 $gitRepo->getRepository ()->addRemote (
"origin", $newRemoteUrl );
82 } elseif ($activeRemoteUrl != $newRemoteUrl) {
83 $gitRepo->getRepository ()->setRemoteUrl (
"origin", $newRemoteUrl );
91 if (
sizeof ( $filesToCommit ) > 0) {
94 $countFilesUpdated = 0;
95 $countFilesIgnored = 0;
97 $repo = $gitRepo->getRepository ();
99 $allFiles = $gitRepo->getFiles ();
100 foreach ( $allFiles as $filename => $uFile ) {
101 if (in_array ( $filename, $filesToCommit )) {
102 $filesToAdd [] = $filename;
106 $countFilesUpdated ++;
110 $countFilesIgnored ++;
115 $repo->addFile ( $filesToAdd );
116 if ($countFilesToAdd > 0) {
117 $messages [] = $countFilesToAdd .
" new file(s) added";
119 if ($countFilesIgnored > 0) {
120 $messages [] = $countFilesIgnored .
" ignored file(s).";
122 if ($countFilesUpdated > 0) {
123 $messages [] = $countFilesUpdated .
" updated file(s).";
129 $repo->commit ( $message );
130 $msg = $this->
showSimpleMessage (
"Commit successfully completed!",
"positive",
"Commit",
"check square", null,
"init-message" );
131 $msg->addList ( $messages );
134 $msg = $this->
showSimpleMessage (
"Nothing to commit!",
"",
"Commit",
"warning circle", null,
"init-message" );
137 echo $this->jquery->compile ( $this->view );
141 $this->jquery->exec (
'$(".to-clear").html("");$(".to-clear-value").val("");',
true );
142 $this->jquery->get ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/refreshFiles",
"#dtGitFiles", [
"attr" =>
"",
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false ] );
143 $this->jquery->get ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/refreshCommits",
"#dtCommits", [
"attr" =>
"",
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false ] );
147 $gitRepo = $this->
_getRepo (
false );
149 if ($gitRepo->setRepoRemoteUrl ()) {
150 $repo = $gitRepo->getRepository ();
151 $repo->push (
"origin master", [
"--set-upstream" ] );
152 $msg = $this->
showSimpleMessage (
"Push successfully completed!",
"positive",
"Push",
"upload", null,
"init-message" );
155 $msg = $this->
showSimpleMessage (
"Check your github settings before pushing! (user name, password or remote url)",
"negative",
"Push",
"upload", null,
"init-message" );
157 }
catch ( GitException $ge ) {
158 $msg = $this->
showSimpleMessage ( $ge->getMessage(),
"negative",
"Push",
"upload", null,
"init-message" );
161 echo $this->jquery->compile ( $this->view );
165 $gitRepo = $this->
_getRepo (
false );
166 $repo = $gitRepo->getRepository ();
168 $msg = $this->
showSimpleMessage (
"Pull successfully completed!",
"positive",
"Pull",
"download", null,
"init-message" );
171 echo $this->jquery->compile ( $this->view );
175 $this->jquery->postFormOnClick (
"#validate-btn", $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/gitIgnoreValidate",
"gitignore-frm",
"#frm" );
176 $this->jquery->execOn (
"click",
"#cancel-btn",
'$("#frm").html("");' );
178 if ($content ===
false) {
179 $content =
"#gitignorefile\n";
181 $this->jquery->renderView ( $this->
_getAdminFiles ()->getViewGitIgnore (), [
"content" => $content ] );
188 $this->jquery->get ( $this->
_getAdminFiles ()->getAdminBaseRoute () .
"/refreshFiles",
"#dtGitFiles", [
"attr" =>
"",
"jqueryDone" =>
"replaceWith",
"hasLoader" =>
false ] );
189 $message = $this->
showSimpleMessage (
"<b>.gitignore</b> file saved !",
"positive",
"gitignore",
"git" );
191 $message = $this->
showSimpleMessage (
"<b>.gitignore</b> file not saved !",
"warning",
"gitignore",
"git" );
195 echo $this->jquery->compile ( $this->view );
200 $files=$gitRepo->getFiles ();
202 $this->jquery->exec(
'$("#lbl-changed").toggle('.((
sizeof($files)>0)?
"true":
"false").
');',
true);
203 echo $this->jquery->compile ( $this->view );
207 $gitRepo = $this->
_getRepo (
false );
208 echo $this->
_getAdminViewer ()->getGitCommitsDataTable ( $gitRepo->getCommits () );
209 echo $this->jquery->compile ( $this->view );
213 $filename = implode ( DS, $filenameParts );
214 $gitRepo = $this->
_getRepo (
false );
215 $changes = $gitRepo->getRepository ()->getChangesInFile ( $filename );
219 $this->jquery->exec (
'var value=\'' . htmlentities ( str_replace (
"'",
"\\'", str_replace (
"\u",
"\\\u", $changes ) ) ) .
'\';$(
"#changes-in-file").html(Diff2Html.getPrettyHtml($(
"<div/>").html(value).text()),{inputFormat:
"diff", showFiles:
true, matching:
"lines"});
', true ); 220 echo '<div
id=
"changes-in-file"></div>
'; 221 echo $this->jquery->compile ( $this->view ); 224 public function changesInCommit($commitHash) { 225 $gitRepo = $this->_getRepo ( false ); 226 $changes = $gitRepo->getRepository ()->getChangesInCommit ( $commitHash ); 227 if (UString::isNull ( $changes )) { 228 $changes = "No change"; 230 $this->jquery->exec ( 'var value=\
'' . htmlentities ( str_replace (
"'",
"\\'", str_replace (
"\u",
"\\\u", $changes ) ) ) .
'\';var diff2htmlUi =
new Diff2HtmlUI({diff: $(
"<div/>").html(value).text()});diff2htmlUi.draw(
"#changes-in-commit", {inputFormat:
"diff", showFiles:
true, matching:
"lines"});diff2htmlUi.fileListCloseable(
"#changes-in-commit",
true);
', true ); 231 echo '<div
id=
"changes-in-commit"></div>
'; 232 echo $this->jquery->compile ( $this->view ); static init($directory, array $params=NULL)
Init repo in directory.
static isPost()
Returns true if the request is sent by the POST method.
loadView($viewName, $pData=NULL, $asString=false)
changesInfiles(... $filenameParts)
static post($key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
static init($getFiles=true)
static openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues)
showConfMessage($content, $type, $itle, $url, $responseElement, $data, $attributes=NULL)
static getApplicationDir()
showSimpleMessage($content, $type, $title=null, $icon="info", $timeout=NULL, $staticName=null)
static asPhpArray($array, $prefix="", $depth=1, $format=false)
static save($filename, $content, $flags=LOCK_EX)