Commit dac3228f authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Merge branch 'ide' of gitlab.com:gitlab-org/gitlab-ce into ide

parents 74777259 727c8a26
...@@ -96,14 +96,18 @@ const Api = { ...@@ -96,14 +96,18 @@ const Api = {
.done(projects => callback(projects)); .done(projects => callback(projects));
}, },
commitMultiple(id, data, callback) { commitMultiple(id, data, callback, token) {
// see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions // see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
const url = Api.buildUrl(Api.commitPath) const url = Api.buildUrl(Api.commitPath)
.replace(':id', id); .replace(':id', id);
return $.ajax({ return $.ajax({
url, url,
headers: {
'PRIVATE_TOKEN': token,
},
type: 'POST', type: 'POST',
data: data, contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: 'json', dataType: 'json',
}) })
.done(commitData => callback(commitData)) .done(commitData => callback(commitData))
......
...@@ -21,6 +21,8 @@ function initRepo() { ...@@ -21,6 +21,8 @@ function initRepo() {
Store.service.refsUrl = repo.dataset.refsUrl; Store.service.refsUrl = repo.dataset.refsUrl;
Store.currentBranch = $("button.dropdown-menu-toggle").attr('data-ref'); Store.currentBranch = $("button.dropdown-menu-toggle").attr('data-ref');
Store.checkIsCommitable(); Store.checkIsCommitable();
Store.projectId = repo.dataset.projectId;
Store.tempPrivateToken = repo.dataset.tempToken;
new Vue({ new Vue({
el: repo, el: repo,
......
<script> <script>
import Vue from 'vue'; import Vue from 'vue';
import Store from './repo_store'; import Store from './repo_store';
import Api from '../api'
const RepoCommitSection = { const RepoCommitSection = {
data: () => Store, data: () => Store,
...@@ -8,11 +9,6 @@ const RepoCommitSection = { ...@@ -8,11 +9,6 @@ const RepoCommitSection = {
methods: { methods: {
makeCommit() { makeCommit() {
// see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions // see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
// branch string
// commit_message string
// actions[]
// author_email
// author_name
const branch = $("button.dropdown-menu-toggle").attr('data-ref'); const branch = $("button.dropdown-menu-toggle").attr('data-ref');
const commitMessage = this.commitMessage; const commitMessage = this.commitMessage;
const actions = this.changedFiles.map(f => { const actions = this.changedFiles.map(f => {
...@@ -28,7 +24,18 @@ const RepoCommitSection = { ...@@ -28,7 +24,18 @@ const RepoCommitSection = {
commit_message: commitMessage, commit_message: commitMessage,
actions: actions, actions: actions,
} }
console.log(branch, commitMessage, actions); Store.submitCommitsLoading = true;
Api.commitMultiple(Store.projectId, payload, (data) => {
Store.submitCommitsLoading = false;
Flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice');
console.log('this.changedFiles', this.changedFiles);
console.log('this.files', this.files);
this.changedFiles = [];
this.openedFiles = [];
this.commitMessage = '';
this.editMode = false;
$('html, body').animate({ scrollTop: 0 }, 'fast');
}, Store.tempPrivateToken);
} }
}, },
...@@ -104,7 +111,10 @@ export default RepoCommitSection; ...@@ -104,7 +111,10 @@ export default RepoCommitSection;
</div> </div>
</div> </div>
<div class="col-md-offset-4 col-md-4"> <div class="col-md-offset-4 col-md-4">
<button type="submit" :disabled="!commitMessage" class="btn btn-success" @click.prevent="makeCommit">Commit {{changedFiles.length}} Files</button> <button type="submit" :disabled="!commitMessage || submitCommitsLoading" class="btn btn-success" @click.prevent="makeCommit">
<i class="fa fa-spinner fa-spin" v-if="submitCommitsLoading"></i>
<span>Commit {{changedFiles.length}} Files</span>
</button>
</div> </div>
</fieldset> </fieldset>
</form> </form>
......
...@@ -73,17 +73,15 @@ const RepoHelper = { ...@@ -73,17 +73,15 @@ const RepoHelper = {
}, },
getNewMergedList(inDirectory, currentList, newList) { getNewMergedList(inDirectory, currentList, newList) {
if (!inDirectory) return newList; const newListSorted = newList.sort(this.compareFilesCaseInsensitive);
if (!inDirectory) return newListSorted;
const indexOfFile = currentList.findIndex(file => file.url === inDirectory.url); const indexOfFile = currentList.findIndex(file => file.url === inDirectory.url);
if (!indexOfFile) return newListSorted;
if (!indexOfFile) return newList; return RepoHelper.mergeNewListToOldList(newListSorted, currentList, inDirectory, indexOfFile);
return RepoHelper.mergeNewListToOldList(newList, currentList, inDirectory, indexOfFile);
}, },
mergeNewListToOldList(newList, oldList, inDirectory, indexOfFile) { mergeNewListToOldList(newList, oldList, inDirectory, indexOfFile) {
newList.forEach((newFile) => { newList.reverse().forEach((newFile) => {
const fileIndex = indexOfFile + 1; const fileIndex = indexOfFile + 1;
const file = newFile; const file = newFile;
file.level = inDirectory.level + 1; file.level = inDirectory.level + 1;
...@@ -93,6 +91,17 @@ const RepoHelper = { ...@@ -93,6 +91,17 @@ const RepoHelper = {
return oldList; return oldList;
}, },
compareFilesCaseInsensitive(a,b) {
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if(a.level > 0) return 0;
if (aName < bName)
return -1;
if (aName > bName)
return 1;
return 0;
},
getContent(treeOrFile, cb) { getContent(treeOrFile, cb) {
let file = treeOrFile; let file = treeOrFile;
// const loadingData = RepoHelper.setLoading(true); // const loadingData = RepoHelper.setLoading(true);
......
...@@ -10,6 +10,7 @@ const RepoStore = { ...@@ -10,6 +10,7 @@ const RepoStore = {
editMode: false, editMode: false,
isTree: false, isTree: false,
prevURL: '', prevURL: '',
projectId: '',
projectName: '', projectName: '',
trees: [], trees: [],
blobs: [], blobs: [],
...@@ -21,6 +22,8 @@ const RepoStore = { ...@@ -21,6 +22,8 @@ const RepoStore = {
defaultTabSize: 100, defaultTabSize: 100,
minTabSize: 30, minTabSize: 30,
tabsOverflow: 41, tabsOverflow: 41,
tempPrivateToken: '',
submitCommitsLoading: false,
activeFile: { activeFile: {
active: true, active: true,
binary: false, binary: false,
......
#repo{ data: { url: repo_url(@project), 'project-name' => @project.name, refs_url: refs_namespace_project_path(@project.namespace, @project, format: "json"), project_url: namespace_project_path(@project.namespace, @project) } } #repo{ data: { url: repo_url(@project), 'project-name' => @project.name, refs_url: refs_namespace_project_path(@project.namespace, @project, format: "json"), project_url: namespace_project_path(@project.namespace, @project), project_id: @project.id, temp_token: @current_user.private_token } }
- if can_edit_tree? - if can_edit_tree?
= render 'projects/blob/upload', title: _('Upload New File'), placeholder: _('Upload New File'), button_title: _('Upload file'), form_path: project_create_blob_path(@project, @id), method: :post = render 'projects/blob/upload', title: _('Upload New File'), placeholder: _('Upload New File'), button_title: _('Upload file'), form_path: project_create_blob_path(@project, @id), method: :post
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment