gitprep / templates / settings.html.ep /
Newer Older
317 lines | 11.047kb
setting page
Yuki Kimoto authored on 2013-03-24
1
<%
add create repository tests
Yuki Kimoto authored on 2013-05-19
2
  # API
added description changed fe...
Yuki Kimoto authored on 2013-03-24
3
  my $api = gitprep_api;
revert encoding support
Yuki Kimoto authored on 2013-11-22
4
  my $manager = app->manager;
add create repository tests
Yuki Kimoto authored on 2013-05-19
5
  
6
  # Parameters
added description changed fe...
Yuki Kimoto authored on 2013-03-24
7
  my $op = param('op') || '';
add create repository tests
Yuki Kimoto authored on 2013-05-19
8
  my $user = param('user') || '';
added description changed fe...
Yuki Kimoto authored on 2013-03-24
9
  
add create repository tests
Yuki Kimoto authored on 2013-05-19
10
  # Authentication
11
  unless ($api->logined($user)) {
12
    $self->redirect_to('/');
cleanup
Yuki Kimoto authored on 2013-05-13
13
    return;
14
  }
added description changed fe...
Yuki Kimoto authored on 2013-03-24
15
  
add create repository tests
Yuki Kimoto authored on 2013-05-19
16
  # Rename project
revert encoding support
Yuki Kimoto authored on 2013-11-22
17
  my $git = app->git;
simplify rename project
Yuki Kimoto authored on 2013-05-22
18
  my $errors;
19
  my $post = lc $self->req->method eq 'post';
20
  if ($op eq 'rename-project' && $post) {
added project rename feature
Yuki Kimoto authored on 2013-03-25
21
  
22
    # Validation
23
    my $params = $api->params;
24
    my $rule = [
simplify rename project
Yuki Kimoto authored on 2013-05-22
25
      'to-project' => [
add rename project and suppr...
Yuki Kimoto authored on 2013-05-24
26
        ['not_blank' => 'Repository name is empty.'],
27
        ['project_name' => 'Repository name contains invalid charactor.']
added project rename feature
Yuki Kimoto authored on 2013-03-25
28
      ]
29
    ];
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
30
    my $vresult = app->vc->validate($params, $rule);
added project rename feature
Yuki Kimoto authored on 2013-03-25
31
    
32
    if ($vresult->is_ok) {
33
      # Valida parameters
34
      my $data = $vresult->data;
simplify rename project
Yuki Kimoto authored on 2013-05-22
35
      my $to_project = $data->{'to-project'};
added project rename feature
Yuki Kimoto authored on 2013-03-25
36
      
37
      # Rename
revert encoding support
Yuki Kimoto authored on 2013-11-22
38
      if (app->manager->exists_project($user, $to_project)) {
simplify rename project
Yuki Kimoto authored on 2013-05-22
39
        $errors = ["$to_project is already exists"];
added project rename feature
Yuki Kimoto authored on 2013-03-25
40
      }
41
      else {
revert encoding support
Yuki Kimoto authored on 2013-11-22
42
        eval { app->manager->rename_project($user, $project, $to_project) };
add private checkbox
Yuki Kimoto authored on 2013-11-16
43
        if (my $e = $@) {
44
          app->log->error($e);
simplify rename project
Yuki Kimoto authored on 2013-05-22
45
          $errors = ['Internal Error'];
46
        }
47
        else {
48
          flash(message => "Repository name is renamed to $to_project");
49
          $self->redirect_to("/$user/$to_project/settings");
50
          return;
51
        }
added project rename feature
Yuki Kimoto authored on 2013-03-25
52
      }
53
    }
simplify rename project
Yuki Kimoto authored on 2013-05-22
54
    else { $errors = $vresult->messages }
added project rename feature
Yuki Kimoto authored on 2013-03-25
55
  }
add create repository tests
Yuki Kimoto authored on 2013-05-19
56
  
57
  # Change description
simplify rename project
Yuki Kimoto authored on 2013-05-22
58
  elsif ($op eq 'change-description' && $post) {
added description changed fe...
Yuki Kimoto authored on 2013-03-24
59
    my $description = param('description');
60
    $description = '' unless defined $description;
61
    
simplify rename project
Yuki Kimoto authored on 2013-05-22
62
    eval { $git->description($user, $project, $description) };
add private checkbox
Yuki Kimoto authored on 2013-11-16
63
    if (my $e = $@) {
64
      app->log->error("/$user/$project/settings?op=description: $e");
simplify rename project
Yuki Kimoto authored on 2013-05-22
65
      $errors = ['Internal Error'];
66
    }
67
    else {
68
      flash(message => 'Description is saved.');
69
      $self->redirect_to('current');
70
      return;
71
    }
added description changed fe...
Yuki Kimoto authored on 2013-03-24
72
  }
add create repository tests
Yuki Kimoto authored on 2013-05-19
73
  
added default branch change ...
Yuki Kimoto authored on 2013-05-22
74
  # Change default branch
75
  elsif ($op eq 'default-branch' && $post) {
76
    my $default_branch = param('default-branch');
revert encoding support
Yuki Kimoto authored on 2013-11-22
77
    eval { app->manager->default_branch($user, $project, $default_branch) };
add private checkbox
Yuki Kimoto authored on 2013-11-16
78
    if (my $e = $@) {
79
      app->log->error("/$user/$project/settings?op=default-branch: $e");
added default branch change ...
Yuki Kimoto authored on 2013-05-22
80
      $errors = ['Internal Error'];
81
    }
82
    else {
83
      flash(message => "Default branch is changed to $default_branch.");
84
      $self->redirect_to('current');
85
      return;
86
    }
87
  }
revert encoding support
Yuki Kimoto authored on 2013-11-22
88
  
add private checkbox
Yuki Kimoto authored on 2013-11-16
89
  # Private repository
90
  elsif ($op eq 'private' && $post) {
91
    my $private = param('private') ? 1 : 0;
92
    
93
    eval {
94
      app->dbi->model('project')->update(
95
        {private => $private},
96
        id => [$user, $project]
97
      );
98
    };
99
    if (my $e = $@) {
100
      app->log->error("/$user/$project/settings?op=private: $e");
101
      $errors = ['Internal Error'];
102
    }
103
    else {
add private repository and c...
Yuki Kimoto authored on 2013-11-18
104
      my $message = 'Private status is saved. Repository is '
105
        . ($private ? 'private' : 'public');
106
      flash(message => $message);
add private checkbox
Yuki Kimoto authored on 2013-11-16
107
      $self->redirect_to('current');
108
      return;
109
    }
110
  }
111
  
add create repository tests
Yuki Kimoto authored on 2013-05-19
112
  # Delete project
simplify rename project
Yuki Kimoto authored on 2013-05-22
113
  elsif ($op eq 'delete-project' && $post) {
added project delete feature
Yuki Kimoto authored on 2013-03-24
114
    
add delete project test
Yuki Kimoto authored on 2013-05-25
115
    my $user = param('user');
116
    my $project = param('project');
117
    
revert encoding support
Yuki Kimoto authored on 2013-11-22
118
    eval { app->manager->delete_project($user, $project) };
add private checkbox
Yuki Kimoto authored on 2013-11-16
119
    if (my $e = $@) {
120
      app->log->error("/$user/$project/settings: $e");
add delete project test
Yuki Kimoto authored on 2013-05-25
121
      $errors = ['Internal Error'];
122
    }
123
    else {
124
      flash(message => "Repository $project is deleted.");
125
      $self->redirect_to("/$user");
126
      return;
added project delete feature
Yuki Kimoto authored on 2013-03-24
127
    }
128
  }
setting page
Yuki Kimoto authored on 2013-03-24
129
%>
130

            
add title
Yuki Kimoto authored on 2013-06-12
131
% layout 'common', title => 'Options';
setting page
Yuki Kimoto authored on 2013-03-24
132
  
added description changed fe...
Yuki Kimoto authored on 2013-03-24
133
  %= javascript begin
added project delete feature
Yuki Kimoto authored on 2013-03-24
134
    
added description changed fe...
Yuki Kimoto authored on 2013-03-24
135
    $(document).ready(function () {
added project delete feature
Yuki Kimoto authored on 2013-03-24
136
    
simplify rename project
Yuki Kimoto authored on 2013-05-22
137
      // Rename project
added project rename feature
Yuki Kimoto authored on 2013-03-25
138
      $('#rename').on('click', function () {
simplify rename project
Yuki Kimoto authored on 2013-05-22
139
        $('#form-rename-project').submit();
added description changed fe...
Yuki Kimoto authored on 2013-03-24
140
      });
141
      
added default branch change ...
Yuki Kimoto authored on 2013-05-22
142
      // Select default branch
143
      $('[name=default-branch]').on('change', function () {
144
        $('#form-default-branch').submit();
145
      });
146

            
added project delete feature
Yuki Kimoto authored on 2013-03-24
147
      // Check matching deleted project
148
      $('input[name="deleted-project"]').on('keyup', function () {
149
        var deleted_project = $(this).val();
150
        var project = "<%= $project %>";
151
        
152
        if (deleted_project == project) {
153
          $('#delete').attr('class', 'btn btn-danger')
154
            .removeAttr('disabled');
155
        }
156
        else {
157
          $('#delete').attr('class', 'btn btn-danger disabled')
158
            .attr('disabled', 'disabled');
159
        }
160
      });
added default branch change ...
Yuki Kimoto authored on 2013-05-22
161
            
added project delete feature
Yuki Kimoto authored on 2013-03-24
162
      // Delete project
163
      $('#delete').on('click', function () {
simplify delete project
Yuki Kimoto authored on 2013-05-23
164
        $('#form-delete-project').submit();
added project delete feature
Yuki Kimoto authored on 2013-03-24
165
      });
added description changed fe...
Yuki Kimoto authored on 2013-03-24
166
    });
167
  % end
168
  
setting page
Yuki Kimoto authored on 2013-03-24
169
  %= include '/include/header';
170
  
171
  <div class="container">
simplify rename project
Yuki Kimoto authored on 2013-05-22
172
    %= include '/include/errors', errors => $errors;
173
    %= include '/include/message', message => flash('message');
setting page
Yuki Kimoto authored on 2013-03-24
174
    %= include '/include/project_header';
175
    
add collaboration page
Yuki Kimoto authored on 2013-11-17
176
    <div class="row">
177
      <div class="span2">
178
        <ul class="unstyled" style="font-size:13px;">
179
          <li class="border-gray" style="padding:5px;"><b>Options</b></li>
180
          <li class="border-gray" style="border-top:none;padding:6px;"><a href="<%= url_for("/$user/$project/settings/collaboration") %>">Collaborators</a></li>
181
        </ul>
setting page
Yuki Kimoto authored on 2013-03-24
182
      </div>
add collaboration page
Yuki Kimoto authored on 2013-11-17
183
      <div class="span10">
184
        <div style="margin-bottom:20px">
185
          <div class="border-gray bk-gray-light radius-top" style="padding-left:5px">
186
            <h4>
187
              Settings
188
            </h4>
simplify rename project
Yuki Kimoto authored on 2013-05-22
189
          </div>
add collaboration page
Yuki Kimoto authored on 2013-11-17
190
          <div class="border-gray" style="padding:5px 10px;border-top:none">
191
            <form id="form-rename-project" action="<%= url_for->query(op => 'rename-project') %>" method="post" style="margin-bottom:0px">
192
              <div >Repository Name</div>
193
              <div>
194
                %= text_field 'to-project' => $project, style => 'margin-top:9px';
195
                <a href="#rename-confirm" role="button" class="btn" data-toggle="modal">
196
                  Rename
197
                </a>
198
              </div>
199
            </form>
simplify rename project
Yuki Kimoto authored on 2013-05-22
200
          </div>
add collaboration page
Yuki Kimoto authored on 2013-11-17
201
          <div class="border-gray" style="padding:5px 10px;border-top:none">
202
            <form action="<%= url_for->query(op => 'change-description') %>" method="post" style="margin-bottom:0px">
203
              <div >Description</div>
204
              <div>
205
                % my $description = $git->description($user, $project);
206
                % $description = '' unless defined $description;
207
                %= text_field 'description' => $description, class => 'span8', style => 'margin-top:9px';
208
                <input type="submit" class="btn" value="Save">
209
              </div>
210
            </form>
211
          </div>
revert encoding support
Yuki Kimoto authored on 2013-11-22
212
          <div class="border-gray radius-bottom" style="padding:5px 10px;border-top:none;">
add collaboration page
Yuki Kimoto authored on 2013-11-17
213
            <form id="form-default-branch" action="<%= url_for->query(op => 'default-branch') %>" method="post" style="margin-bottom:0px">
214
              Default Branch
215
              % my $branches = $git->branches($user, $project);
216
              % my $branch_names = [map { $_->{name} } @$branches];
revert encoding support
Yuki Kimoto authored on 2013-11-22
217
              % my $default_branch = app->manager->default_branch($user, $project);
add collaboration page
Yuki Kimoto authored on 2013-11-17
218
              % push @$branch_names, $default_branch unless @$branch_names;
219
              % param('default-branch', $default_branch);
220
              %= select_field 'default-branch' => $branch_names, style => 'margin-top:5px';
221
            </form>
222
          </div>
223
          <div class="border-gray radius-bottom" style="padding:5px 10px;border-top:none;">
revert encoding support
Yuki Kimoto authored on 2013-11-22
224
            <form id="form-default-branch" action="<%= url_for->query(op => 'private') %>" method="post" style="margin-bottom:0px">
add collaboration page
Yuki Kimoto authored on 2013-11-17
225
              <span>Make this repository private</span>
revert encoding support
Yuki Kimoto authored on 2013-11-22
226
              % my $private = app->manager->is_private_project($user, $project);
add collaboration page
Yuki Kimoto authored on 2013-11-17
227
              % if ($private) {
228
                % param('private', 1);
229
              % }
230
              %= check_box 'private' => 1, style => 'margin-top:0px;margin-left:5px;margin-right:10px';
231
              <input type="submit" class="btn" value="Save">
232
            </form>
233
          </div>
234
        </div>
235
        
236
        <div style="margin-bottom:30px">
237
          <div class="border-gray bk-gray-light radius-top" style="background:red;padding-left:5px">
238
            <h4 style="color:white">Danger Zone</h4>
239
          </div>
240
          <div class="border-gray radius-bottom" style="padding:5px 10px;border-top:none">
241
            <form id="form-delete-project" action="<%= url_for->query(op => 'delete-project') %>" method="post">
242
              <div><b>Delete this repository</b></div>
243
              <span class="muted">
244
                Once you delete a repository, there is no going back.
245
              </span>
246
              <a style="color:red" href="#delete-confirm" role="button" class="btn" data-toggle="modal">
247
                Delete this repository
248
              </a>
249
              %= hidden_field user => $user;
250
              %= hidden_field project => $project;
251
            </form>
252
          </div>
253
        </div>
simplify delete project
Yuki Kimoto authored on 2013-05-23
254
      </div>
setting page
Yuki Kimoto authored on 2013-03-24
255
    </div>
256
  </div>
257
  
move project delete feature ...
Yuki Kimoto authored on 2013-03-27
258
  <div id="modal-message" class="modal hide">
added description changed fe...
Yuki Kimoto authored on 2013-03-24
259
    <div class="modal-header">
move project delete feature ...
Yuki Kimoto authored on 2013-03-27
260
      <div id="modal-message-text" style="font-weight:bold"></div>
added description changed fe...
Yuki Kimoto authored on 2013-03-24
261
    </div>
262
    <div class="modal-body">
263
      <button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>
264
    </div>
265
  </div>
added project rename feature
Yuki Kimoto authored on 2013-03-25
266

            
267
  <div id="rename-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="rename-confirm-label" aria-hidden="true">
268
    <div class="modal-header">
revert encoding support
Yuki Kimoto authored on 2013-11-22
269
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
move project delete feature ...
Yuki Kimoto authored on 2013-03-27
270
      <div style="font-weight:bold">Are you sure you want to rename?</div>
added project rename feature
Yuki Kimoto authored on 2013-03-25
271
    </div>
272
    <div class="modal-body">
273
      <p>
274
        Unexpected bad things will happen if you don't read this
275
      </p>
276
      <ul>
277
        <li>
278
          We will not set up any redirects from the old location
279
        </li>
280
        <li>
281
          You will need to update your local repositories to point to the new location
282
        </li>
283
      </ul>
284
    </div>
285
    <div class="modal-footer">
286
      <button id="rename" class="btn" data-dismiss="modal" aria-hidden="true">
287
        I understand, rename this repository
288
      </button>
289
    </div>
290
  </div>
291

            
added project delete feature
Yuki Kimoto authored on 2013-03-24
292
  <div id="delete-confirm" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-confirm-label" aria-hidden="true">
293
    <div class="modal-header">
revert encoding support
Yuki Kimoto authored on 2013-11-22
294
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
move project delete feature ...
Yuki Kimoto authored on 2013-03-27
295
      <div style="font-weight:bold">Are you ABSOLUTELY sure?</div>
added project delete feature
Yuki Kimoto authored on 2013-03-24
296
    </div>
297
    <div class="modal-body">
298
      <p>
299
        Unexpected bad things will happen if you don't read this.
300
      </p>
301
      <p>
302
        This action <b>CANNOT</b> be undone. This will delete the <b><%= "$user/$project" %></b>
303
        repository, wiki, issues, and comments permanently.
304
      </p>
305
      <p>
306
        Please type in the name of the repository(<b><%= $project %></b>) to confirm.
307
      </p>
308
      %= text_field 'deleted-project', class => 'span5';
309
    </div>
310
    <div class="modal-footer">
311
      <button id="delete" class="btn btn-danger disabled" disabled data-dismiss="modal" aria-hidden="true">
312
        I understand the consequences, delete this repository
313
      </button>
314
    </div>
315
  </div>
added description changed fe...
Yuki Kimoto authored on 2013-03-24
316

            
setting page
Yuki Kimoto authored on 2013-03-24
317
  %= include '/include/footer';