mtrack /web/admin/repo.php

Language PHP Lines 243
MD5 Hash c3ad934fbcc57e349868dd855328afcb Estimated Cost $4,437 (why?)
Repository https://bitbucket.org/yoander/mtrack View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php # vim:ts=2:sw=2:et:
/* For licensing and copyright terms, see the file named LICENSE */
include '../../inc/common.php';

$rid = mtrack_get_pathinfo();

mtrack_head("Administration - Repositories");
mtrack_admin_nav();
if (!strlen($rid)) {
  MTrackACL::requireAnyRights('Browser', 'modify');
?>
<h1>Repositories</h1>

<p>
Repositories are version controlled folders that remember your files and
folders at various points in time.  Mtrack has support for multiple different
Software Configuration Management systems (also known as Version Control
Systems; SCM and VCS are the common acronyms).
</p>
<p>
Listed below are the repositories that mtrack is configured to use.
The <em>wiki</em> repository is treated specially by mtrack; it stores the
wiki pages.  Click on the repository name to edit it, or click on the "Add"
button to tell mtrack to use another repository.
</p>
<ul id='repolist' class='nav'></ul>
<?php
  $repos = json_encode(MTrackAPI::invoke('GET', '/repo/properties')->result);
  echo <<<HTML
  <script>
$(document).ready(function () {
  var repos = new MTrackRepoList($repos);

  function addOne(R) {
    var ul = $('#repolist');
    var li = $('<li/>');
    var name = $('<a/>');
    name.text(R.get('browsepath'));
    name.attr('href', '#');//ABSWEB + 'admin/repo.php/' + R.id);
    li.append(name);
    li.data('model', R);
    ul.append(li);
  }

  repos.bind('add', function (R) {
    addOne(R);
  });
  repos.bind('remove', function (R) {
    draw_list();
  });

  function show_repo_dlg(R) {
    var V = new MTrackRepoEditView({
      model: R
    });
    V.show(function () {
      repos.add(R, {at: repos.length});
    });
  }

  function draw_list() {
    var ul = $('#repolist');
    ul.empty();

    repos.each(function (R) {
      addOne(R);
    });
  }
  draw_list();

  $('ul#repolist').on('click', 'a', function() {
    var R = $(this).closest('li').data('model');
    var V = new MTrackRepoEditView({
      model: R
    });
    V.show(function (model) {
    });

    return false;
  });

  $('#newrepobtn').click(function () {
    var R = new MTrackRepo;
    show_repo_dlg(R);
  });
});
</script>
HTML;

  if (MTrackACL::hasAnyRights('Browser', 'create')) {
    echo "<button id='newrepobtn' class='btn btn-primary'><i class='icon-white icon-plus'></i> New Repo</button>";
  }
  mtrack_foot();
  exit;
}

$repotypes = array();
foreach (MTrackRepo::getAvailableSCMs() as $t => $r) {
  $d = $r->getSCMMetaData();
  $repotypes[$t] = $d['name'];
}

echo "<form method='post'>";

if ($rid == 'new') {
  MTrackACL::requireAnyRights('Browser', 'create');
?>
<h2>Add new or existing Repository</h2>
<p>
  Use the form below to tell mtrack where to find an existing
  repository and add it to its list.  Leave the "Path" field
  blank to create a new repository.
</p>
<table>
<?php
  echo "<tr><th>Name</th>" .
    "<td><input type='text' name='repo:name' value=''></td>" .
    "</tr>";
  echo "<tr><th>Type</th>" .
    "<td>" .
    mtrack_select_box("repo:type", $repotypes, null, true) .
    "</td></tr>\n";
  echo "<tr><th>Path</th>" .
    "<td><input type='text' name='repo:path' size='50' value=''></td>" .
    "</tr>\n";
  echo "<tr><td colspan='2'>Description<br><em>You may use <a href='{$ABSWEB}help.php/WikiFormatting' target='_blank'>WikiFormatting</a></em><br>\n";
  echo "<textarea name='repo:description' class='wiki shortwiki' rows='5' cols='78'>";
  echo "</textarea></td></tr>\n";
  echo "</table>";
} else {
  $P = MTrackRepo::loadById($rid);
  MTrackACL::requireAnyRights("repo:$P->repoid", 'modify');

  $name = htmlentities($P->shortname, ENT_QUOTES, 'utf-8');
  $type = htmlentities($P->scmtype, ENT_QUOTES, 'utf-8');
  $path = htmlentities($P->repopath, ENT_QUOTES, 'utf-8');
  $desc = htmlentities($P->description, ENT_QUOTES, 'utf-8');

  echo "<h2>Repository: $name</h2>\n";
  echo "<table>\n";

  if (!$P->parent) {
    /* not created/managed by us; some fields are editable */
    $name = "<input type='text' name='repo:name' value='$name'>";
    $type = mtrack_select_box("repo:type", $repotypes, $type);
    $path = "<input type='text' name='repo:path' size='50' value='$path'>";
  } else {
    $name = htmlentities($P->getBrowseRootName(), ENT_QUOTES, 'utf-8');
  }

  echo "<tr><th>Name</th><td>$name</td></tr>";
  echo "<tr><th>Type</th><td>$type</td></tr>\n";
  echo "<tr><th>Path</th><td>$path</td></tr>\n";
  echo "<tr><td colspan='2'>Description<br><em>You may use <a href='{$ABSWEB}help.php/WikiFormatting' target='_blank'>WikiFormatting</a></em><br>\n";
  echo "<textarea name='repo:description' class='wiki shortwiki' rows='5' cols='78'>$desc";
  echo "</textarea></td></tr>\n";

  echo "<tr><td colspan='2'>\n";

  $action_map = array(
    'Web' => array(
      'read'   => 'Browse via web UI',
      'modify' => 'Administer via web UI',
      'delete' => 'Delete repo via web UI',
    ),
    'SSH' => array(
      'checkout' => 'Check-out repo via SSH',
      'commit' => 'Commit changes to repo via SSH',
    ),
  );

  MTrackACL::renderACLForm('perms', "repo:$P->repoid", $action_map);

  echo "</tr>\n";
  echo "</table>";
}

$projects = array();
foreach (MTrackDB::q('select projid, name, shortname from projects
    order by name')->fetchAll() as $row) {
  if ($row[1] != $row[2]) {
    $projects[$row[0]] = $row[1] . " ($row[2])";
  } else {
    $projects[$row[0]] = $row[1];
  }
}

if (count($projects)) {

  echo <<<HTML
<h3>Linked Projects</h3>
<p>
Project links help associate code changes made in a repository with a project,
and this in turn helps mtrack decide who to notify about the change.
</p>
<p>
When assessing a change, mtrack will try each regex listed below and then take
the project that corresponds with the longest match--not the longest pattern;
the longest actual match.
</p>
<p>
The regex should just be the bare regex string--you must not enclose it in
regex delimiters.
</p>
<p>
You can remove a link by setting the regex to the empty string.
</p>
HTML;

  echo "<table>";
  echo "<tr><th>Regex</th><th>Project</th></tr>\n";

  if ($rid != 'new') {
    foreach ($P->getLinks() as $lid => $n) {
      list($pid, $regex) = $n;

      $regex = htmlentities($regex, ENT_QUOTES, 'utf-8');
      echo "<tr><td>" .
        "<input type='text' name='link:$lid:regex' value='$regex'></td>".
        "<td>" . mtrack_select_box("link:$lid:project", $projects, $pid) .
        "</td></tr>\n";
    }
  }

  if ($rid == 'new') {
    $newre = '/';
  } else {
    $newre = '';
  }

  echo "<tr><td>" .
    "<input type='text' name='link:new:regex' value='$newre'></td>".
    "<td>" . mtrack_select_box("link:new:project", $projects) .
    "</td><td>Add new link</td></tr>\n";

  echo "</table>";
}

echo "<button>Save Changes</button></form>";

mtrack_foot();
Back to Top