[Notice] Announcing the End of Demo Server [Read me]
김덕홍 2014-08-07
Merge branch 'issue-1662' of dlab/hive
from pull request 1213
@58c0e597645d2cce20aef32c578b28f58e3c4ce0
app/controllers/ProjectApp.java
--- app/controllers/ProjectApp.java
+++ app/controllers/ProjectApp.java
@@ -68,6 +68,7 @@
 import views.html.project.home;
 import views.html.project.setting;
 import views.html.project.transfer;
+import views.html.project.change_vcs;
 
 import javax.servlet.ServletException;
 
@@ -629,6 +630,27 @@
         return redirect(routes.ProjectApp.project(project.owner, project.name));
     }
 
+    @IsAllowed(Operation.UPDATE)
+    public static Result changeVCSForm(String ownerId, String projectName) {
+        Project project = Project.findByOwnerAndProjectName(ownerId, projectName);
+        Form<Project> projectForm = form(Project.class).fill(project);
+        return ok(change_vcs.render("title.projectChangeVCS", projectForm, project));
+    }
+
+    @IsAllowed(Operation.UPDATE)
+    public static Result changeVCS(String ownerId, String projectName) throws Exception {
+        Project project = Project.findByOwnerAndProjectName(ownerId, projectName);
+        try {
+            project.changeVCS();
+            String url = routes.ProjectApp.project(ownerId, projectName).url();
+            response().setHeader("Location", url);
+            return noContent();
+        } catch (Exception e) {
+            Logger.error(e.getMessage());
+        }
+        return internalServerError();
+    }
+
     private static void sendTransferRequestMail(ProjectTransfer pt) {
         HtmlEmail email = new HtmlEmail();
         try {
app/models/Project.java
--- app/models/Project.java
+++ app/models/Project.java
@@ -558,6 +558,20 @@
         }
     }
 
+    public void changeVCS() throws Exception {
+        if(this.forkingProjects != null) {
+            for(Project fork : forkingProjects) {
+                fork.originalProject = null;
+                fork.update();
+            }
+        }
+
+        RepositoryService.deleteRepository(this);
+        this.vcs = nextVCS();
+        RepositoryService.getRepository(this).create();
+        this.update();
+    }
+
     public enum State {
         PUBLIC, PRIVATE, ALL
     }
@@ -750,4 +764,12 @@
     public boolean isPrivate() {
         return projectScope == ProjectScope.PRIVATE;
     }
+
+    public String nextVCS() {
+        if(this.vcs.equals(RepositoryService.VCS_GIT)) {
+            return RepositoryService.VCS_SUBVERSION;
+        } else {
+            return RepositoryService.VCS_GIT;
+        }
+    }
 }
 
app/views/project/change_vcs.scala.html (added)
+++ app/views/project/change_vcs.scala.html
@@ -0,0 +1,85 @@
+@**
+* Yobi, Project Hosting SW
+*
+* Copyright 2014 NAVER Corp.
+* http://yobi.io
+*
+* @Author Keesun
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+**@
+@(message: String)(projectForm: Form[Project], project:Project)
+
+@import helper._
+@import utils.TemplateHelper._
+
+@projectLayout(message, project, utils.MenuType.PROJECT_SETTING) {
+@projectMenu(project, utils.MenuType.PROJECT_SETTING, "")
+<div class="page-wrap-outer">
+    <div class="project-page-wrap">
+        @partial_settingmenu(project)
+        <div class="bubble-wrap gray wp">
+            <div class="row-fluid">
+                <div class="cu-label">@Messages("project.changeVCS.current.vcs")</div>
+                <div class="cu-desc">
+                    <p>
+                        @project.vcs
+                    </p>
+                </div>
+            </div>
+            <div class="row-fluid">
+                <div class="cu-label">@Messages("project.changeVCS")</div>
+                <div class="cu-desc">
+                    <ul>
+                        <li class="notice"><strong>@Messages("project.changeVCS.description1", project.nextVCS)</strong></li>
+                        <li class="notice"><strong>@Messages("project.changeVCS.description2")</strong></li>
+                    </ul>
+                    <p>
+                        <input id="acceptChangeVCS" type="checkbox" class="checkbox" autocomplete="off">
+                        <label for="acceptChangeVCS" class="bg-checkbox label-agreement">@Messages("project.changeVCS.accept")</label>
+                    </p>
+                </div>
+            </div>
+        </div>
+        <div class="box-wrap bottom">
+            <a id="btnChangeVCS" href="#alertChangeVCS" class="ybtn ybtn-danger" data-toggle="modal">
+                <i class="yobicon-database"></i> @Messages("project.changeVCS.this")
+            </a>
+        </div>
+
+        @** Confirm to transfer project **@
+        <div id="alertChangeVCS" class="modal hide">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal">×</button>
+                <h3>@Messages("project.changeVCS.requestion", project.nextVCS)</h3>
+            </div>
+            <div class="modal-body">
+                <p>@Messages("project.changeVCS.description2")</p>
+                <p>@Messages("project.changeVCS.reaccept")</p>
+            </div>
+            <div class="modal-footer">
+                <button id="btnChangeVCSExec" type="button" class="ybtn ybtn-danger">@Messages("button.yes")</button>
+                <button type="button" class="ybtn" data-dismiss="modal">@Messages("button.no")</button>
+            </div>
+        </div>
+        @** // -- // **@
+    </div>
+</div>
+<script type="text/javascript">
+    $(document).ready(function(){
+        $yobi.loadModule("project.ChangeVCS", {
+            "sTransferURL": "@routes.ProjectApp.changeVCS(project.owner, project.name)"
+        });
+    });
+</script>
+}
app/views/project/partial_settingmenu.scala.html
--- app/views/project/partial_settingmenu.scala.html
+++ app/views/project/partial_settingmenu.scala.html
@@ -40,4 +40,5 @@
     @makeSubMenu(routes.IssueLabelApp.labelsForm(project.owner, project.name),    Messages("issue.label"), 0)
     @makeSubMenu(routes.ProjectApp.transferForm(project.owner, project.name), Messages("project.transfer"), 0)
     @makeSubMenu(routes.ProjectApp.deleteForm(project.owner, project.name),   Messages("project.delete"), 0)
+    @makeSubMenu(routes.ProjectApp.changeVCS(project.owner, project.name),   Messages("project.changeVCS"), 0)
 </ul>
conf/messages
--- conf/messages
+++ conf/messages
@@ -445,6 +445,16 @@
 post.write = Write
 project.all = ALL
 project.belongsToMe = Project members.
+project.changeVCS = Repository Type Change
+project.changeVCS.accept = I agree with changing the repository type.
+project.changeVCS.alert = You should agree with changing the repository type.
+project.changeVCS.current.vcs = Current Repository Type
+project.changeVCS.description1 = Changing the repository to {0}.
+project.changeVCS.description2 = If change the repository, All code and history will be deleted.
+project.changeVCS.error = Cann''t Repository Type
+project.changeVCS.requestion = Do you want to change the repository to {0}?
+project.changeVCS.reaccept = Are you sure?
+project.changeVCS.this = Change Repository Type.
 project.codeUpdate = Latest code update
 project.create = Create a project
 project.created = Created date
@@ -454,7 +464,7 @@
 project.dashboard.openIssuesByAssignee = Open issues: by assignee
 project.dashboard.openIssuesByLabel = Open issues: by label
 project.dashboard.openIssuesByMilestone = Open issues: by milestone
-project.dashboard.pullRequests = Open pull requests
+project.dashboard.pullRequests = pen pull requests
 project.default.group.member = Participating projects as member
 project.default.group.watching = Watching projects
 project.defaultBranch.placeholder = Enter default branch
@@ -780,6 +790,7 @@
 title.post.notExistingPage = Page not found
 title.privateProject = Private repositories
 title.project = Project
+title.projectChangeVCS= Repository Change
 title.projectDashboard = Project dashboard
 title.projectDelete = Delete project
 title.projectHome = Project home
conf/messages.ko
--- conf/messages.ko
+++ conf/messages.ko
@@ -446,6 +446,16 @@
 post.write = 글쓰기
 project.all = 모든
 project.belongsToMe = 프로젝트 멤버
+project.changeVCS = 코드 저장소 타입 변경
+project.changeVCS.accept = 코드 저장소 타입을 변경하는데 동의합니다.
+project.changeVCS.alert = 코드 저장소 타입 변경에 동의해야 합니다.
+project.changeVCS.current.vcs = 현재 사용중인 코드 저장소 타입
+project.changeVCS.description1 = 코드 저장소 타입을 {0}으로 변경합니다.
+project.changeVCS.description2 = 코드 저장소 타입을 변경하면 현재 코드와 변경내역을 삭제합니다.
+project.changeVCS.error = 코드 저장소를 변경할 수 없습니다.
+project.changeVCS.requestion = 코드 저장소 타입을 {0}으로 변경하시겠습니까?
+project.changeVCS.reaccept = 정말로 변경하시겠습니까?
+project.changeVCS.this = 코드 저장소 타입을 변경합니다.
 project.codeUpdate = 마지막 코드 업데이트
 project.create = 프로젝트 생성
 project.created = 생성일
@@ -570,7 +580,7 @@
 project.transfer.this = 프로젝트를 이관합니다.
 project.unwatch = 그만 지켜보기
 project.unwatch.start = 프로젝트를 더 이상 지켜보지 않습니다
-project.vcs = 코드 관리 시스템
+project.vcs = 코드 저장소 타입
 project.watch = 지켜보기
 project.watching = 지켜보기 중
 project.you.are.not.watching = {0} 프로젝트를 지켜보고 있지 않습니다.
@@ -781,6 +791,7 @@
 title.post.notExistingPage = 페이지를 찾지 못했습니다.
 title.privateProject = 비공개 프로젝트
 title.project = 프로젝트
+title.projectChangeVCS= 코드 저장소 타입 변경
 title.projectDashboard = 프로젝트 대시보드
 title.projectDelete = 프로젝트 삭제
 title.projectHome = 홈
conf/routes
--- conf/routes
+++ conf/routes
@@ -140,6 +140,8 @@
 PUT            /:user/:project/transfer                                               controllers.ProjectApp.transferProject(user, project)
 GET            /project/transfer/:id/:key                                             controllers.ProjectApp.acceptTransfer(id: Long, key)
 GET            /:user/:project/search                                                 controllers.SearchApp.searchInAProject(user, project)
+GET            /:user/:project/changeVCS                                              controllers.ProjectApp.changeVCSForm(user, project)
+POST           /:user/:project/changeVCS                                              controllers.ProjectApp.changeVCS(user, project)
 
 # Project Review Menu
 GET            /:user/:project/reviews                                                controllers.ReviewThreadApp.reviewThreads(user, project)
 
public/javascripts/service/yobi.project.ChangeVCS.js (added)
+++ public/javascripts/service/yobi.project.ChangeVCS.js
@@ -0,0 +1,85 @@
+/**
+ * Yobi, Project Hosting SW
+ *
+ * Copyright 2014 NAVER Corp.
+ * http://yobi.io
+ *
+ * @Author Keesun Baik
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+(function(ns){
+
+    var NO_CONTENT = 204;
+    var oNS = $yobi.createNamespace(ns);
+    oNS.container[oNS.name] = function(options){
+                
+        var elements = {};
+        
+        /**
+         * initialize
+         */
+        function _init(options){
+            _initElement(options);
+            _attachEvent(options);
+        }
+        
+        /**
+         * initialize element variables
+         */
+        function _initElement(optinos){
+            elements.acceptChangeVCS = $("#acceptChangeVCS");
+            elements.btnChangeVCS = $("#btnChangeVCS");
+            elements.btnChangeVCSExec = $("#btnChangeVCSExec");
+        }
+
+        /**
+         * attach event handlers
+         */
+        function _attachEvent(options){
+            elements.btnChangeVCS.on('click', showConfirmPopup);
+            elements.btnChangeVCSExec.on("click", changeVCS);
+        }
+        
+        function showConfirmPopup() {
+            if(elements.acceptChangeVCS.is(":checked") === false){
+                $yobi.alert(Messages("project.changeVCS.alert"));
+                return false;
+            }
+            return true;
+        }
+
+        function changeVCS() {
+            $.ajax(options.sTransferURL, {
+                "method" : "post",
+                "success": function(res, status, xhr){
+                    // default action below:
+                    var location = xhr.getResponseHeader("Location");
+
+                    if(xhr.status === NO_CONTENT && location){
+                        document.location.href = location;
+                    } else {
+                        document.location.reload();
+                    }
+                },
+                "error": function(){
+                    $("#alertChangeVCS").modal("hide");
+                    $yobi.alert(Messages("project.changeVCS.error"));
+                }
+            });
+        }
+
+        _init(options || {});
+    };
+    
+})("yobi.project.ChangeVCS");
Add a comment
List