PageRenderTime 3347ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/web/admin/repo.php

https://bitbucket.org/dhobsd/mtrack
PHP | 242 lines | 205 code | 35 blank | 2 comment | 17 complexity | c3ad934fbcc57e349868dd855328afcb MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php # vim:ts=2:sw=2:et:
  2. /* For licensing and copyright terms, see the file named LICENSE */
  3. include '../../inc/common.php';
  4. $rid = mtrack_get_pathinfo();
  5. mtrack_head("Administration - Repositories");
  6. mtrack_admin_nav();
  7. if (!strlen($rid)) {
  8. MTrackACL::requireAnyRights('Browser', 'modify');
  9. ?>
  10. <h1>Repositories</h1>
  11. <p>
  12. Repositories are version controlled folders that remember your files and
  13. folders at various points in time. Mtrack has support for multiple different
  14. Software Configuration Management systems (also known as Version Control
  15. Systems; SCM and VCS are the common acronyms).
  16. </p>
  17. <p>
  18. Listed below are the repositories that mtrack is configured to use.
  19. The <em>wiki</em> repository is treated specially by mtrack; it stores the
  20. wiki pages. Click on the repository name to edit it, or click on the "Add"
  21. button to tell mtrack to use another repository.
  22. </p>
  23. <ul id='repolist' class='nav'></ul>
  24. <?php
  25. $repos = json_encode(MTrackAPI::invoke('GET', '/repo/properties')->result);
  26. echo <<<HTML
  27. <script>
  28. $(document).ready(function () {
  29. var repos = new MTrackRepoList($repos);
  30. function addOne(R) {
  31. var ul = $('#repolist');
  32. var li = $('<li/>');
  33. var name = $('<a/>');
  34. name.text(R.get('browsepath'));
  35. name.attr('href', '#');//ABSWEB + 'admin/repo.php/' + R.id);
  36. li.append(name);
  37. li.data('model', R);
  38. ul.append(li);
  39. }
  40. repos.bind('add', function (R) {
  41. addOne(R);
  42. });
  43. repos.bind('remove', function (R) {
  44. draw_list();
  45. });
  46. function show_repo_dlg(R) {
  47. var V = new MTrackRepoEditView({
  48. model: R
  49. });
  50. V.show(function () {
  51. repos.add(R, {at: repos.length});
  52. });
  53. }
  54. function draw_list() {
  55. var ul = $('#repolist');
  56. ul.empty();
  57. repos.each(function (R) {
  58. addOne(R);
  59. });
  60. }
  61. draw_list();
  62. $('ul#repolist').on('click', 'a', function() {
  63. var R = $(this).closest('li').data('model');
  64. var V = new MTrackRepoEditView({
  65. model: R
  66. });
  67. V.show(function (model) {
  68. });
  69. return false;
  70. });
  71. $('#newrepobtn').click(function () {
  72. var R = new MTrackRepo;
  73. show_repo_dlg(R);
  74. });
  75. });
  76. </script>
  77. HTML;
  78. if (MTrackACL::hasAnyRights('Browser', 'create')) {
  79. echo "<button id='newrepobtn' class='btn btn-primary'><i class='icon-white icon-plus'></i> New Repo</button>";
  80. }
  81. mtrack_foot();
  82. exit;
  83. }
  84. $repotypes = array();
  85. foreach (MTrackRepo::getAvailableSCMs() as $t => $r) {
  86. $d = $r->getSCMMetaData();
  87. $repotypes[$t] = $d['name'];
  88. }
  89. echo "<form method='post'>";
  90. if ($rid == 'new') {
  91. MTrackACL::requireAnyRights('Browser', 'create');
  92. ?>
  93. <h2>Add new or existing Repository</h2>
  94. <p>
  95. Use the form below to tell mtrack where to find an existing
  96. repository and add it to its list. Leave the "Path" field
  97. blank to create a new repository.
  98. </p>
  99. <table>
  100. <?php
  101. echo "<tr><th>Name</th>" .
  102. "<td><input type='text' name='repo:name' value=''></td>" .
  103. "</tr>";
  104. echo "<tr><th>Type</th>" .
  105. "<td>" .
  106. mtrack_select_box("repo:type", $repotypes, null, true) .
  107. "</td></tr>\n";
  108. echo "<tr><th>Path</th>" .
  109. "<td><input type='text' name='repo:path' size='50' value=''></td>" .
  110. "</tr>\n";
  111. echo "<tr><td colspan='2'>Description<br><em>You may use <a href='{$ABSWEB}help.php/WikiFormatting' target='_blank'>WikiFormatting</a></em><br>\n";
  112. echo "<textarea name='repo:description' class='wiki shortwiki' rows='5' cols='78'>";
  113. echo "</textarea></td></tr>\n";
  114. echo "</table>";
  115. } else {
  116. $P = MTrackRepo::loadById($rid);
  117. MTrackACL::requireAnyRights("repo:$P->repoid", 'modify');
  118. $name = htmlentities($P->shortname, ENT_QUOTES, 'utf-8');
  119. $type = htmlentities($P->scmtype, ENT_QUOTES, 'utf-8');
  120. $path = htmlentities($P->repopath, ENT_QUOTES, 'utf-8');
  121. $desc = htmlentities($P->description, ENT_QUOTES, 'utf-8');
  122. echo "<h2>Repository: $name</h2>\n";
  123. echo "<table>\n";
  124. if (!$P->parent) {
  125. /* not created/managed by us; some fields are editable */
  126. $name = "<input type='text' name='repo:name' value='$name'>";
  127. $type = mtrack_select_box("repo:type", $repotypes, $type);
  128. $path = "<input type='text' name='repo:path' size='50' value='$path'>";
  129. } else {
  130. $name = htmlentities($P->getBrowseRootName(), ENT_QUOTES, 'utf-8');
  131. }
  132. echo "<tr><th>Name</th><td>$name</td></tr>";
  133. echo "<tr><th>Type</th><td>$type</td></tr>\n";
  134. echo "<tr><th>Path</th><td>$path</td></tr>\n";
  135. echo "<tr><td colspan='2'>Description<br><em>You may use <a href='{$ABSWEB}help.php/WikiFormatting' target='_blank'>WikiFormatting</a></em><br>\n";
  136. echo "<textarea name='repo:description' class='wiki shortwiki' rows='5' cols='78'>$desc";
  137. echo "</textarea></td></tr>\n";
  138. echo "<tr><td colspan='2'>\n";
  139. $action_map = array(
  140. 'Web' => array(
  141. 'read' => 'Browse via web UI',
  142. 'modify' => 'Administer via web UI',
  143. 'delete' => 'Delete repo via web UI',
  144. ),
  145. 'SSH' => array(
  146. 'checkout' => 'Check-out repo via SSH',
  147. 'commit' => 'Commit changes to repo via SSH',
  148. ),
  149. );
  150. MTrackACL::renderACLForm('perms', "repo:$P->repoid", $action_map);
  151. echo "</tr>\n";
  152. echo "</table>";
  153. }
  154. $projects = array();
  155. foreach (MTrackDB::q('select projid, name, shortname from projects
  156. order by name')->fetchAll() as $row) {
  157. if ($row[1] != $row[2]) {
  158. $projects[$row[0]] = $row[1] . " ($row[2])";
  159. } else {
  160. $projects[$row[0]] = $row[1];
  161. }
  162. }
  163. if (count($projects)) {
  164. echo <<<HTML
  165. <h3>Linked Projects</h3>
  166. <p>
  167. Project links help associate code changes made in a repository with a project,
  168. and this in turn helps mtrack decide who to notify about the change.
  169. </p>
  170. <p>
  171. When assessing a change, mtrack will try each regex listed below and then take
  172. the project that corresponds with the longest match--not the longest pattern;
  173. the longest actual match.
  174. </p>
  175. <p>
  176. The regex should just be the bare regex string--you must not enclose it in
  177. regex delimiters.
  178. </p>
  179. <p>
  180. You can remove a link by setting the regex to the empty string.
  181. </p>
  182. HTML;
  183. echo "<table>";
  184. echo "<tr><th>Regex</th><th>Project</th></tr>\n";
  185. if ($rid != 'new') {
  186. foreach ($P->getLinks() as $lid => $n) {
  187. list($pid, $regex) = $n;
  188. $regex = htmlentities($regex, ENT_QUOTES, 'utf-8');
  189. echo "<tr><td>" .
  190. "<input type='text' name='link:$lid:regex' value='$regex'></td>".
  191. "<td>" . mtrack_select_box("link:$lid:project", $projects, $pid) .
  192. "</td></tr>\n";
  193. }
  194. }
  195. if ($rid == 'new') {
  196. $newre = '/';
  197. } else {
  198. $newre = '';
  199. }
  200. echo "<tr><td>" .
  201. "<input type='text' name='link:new:regex' value='$newre'></td>".
  202. "<td>" . mtrack_select_box("link:new:project", $projects) .
  203. "</td><td>Add new link</td></tr>\n";
  204. echo "</table>";
  205. }
  206. echo "<button>Save Changes</button></form>";
  207. mtrack_foot();