PageRenderTime 371ms CodeModel.GetById 92ms app.highlight 215ms RepoModel.GetById 52ms app.codeStats 1ms

/web/admin/repo.php

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