Commit af9d41c5 authored by Ivanq's avatar Ivanq

Merge branch 'edit'

parents 1d5af7ee 35c83382
......@@ -630,6 +630,9 @@ class Git {
});
});
}
setRef(ref, commit) {
return this.writeFile(ref, this.stringToArray(commit));
}
getBranchCommit(branch) {
// Fallback for branch id
if(this.isSha(branch)) {
......
......@@ -12,7 +12,7 @@ You can either call `readUnknownObject` multiple times or run `readTreeItem(root
### How can I get ref list?
Use `getRefList` which returns an array like `["refs/remotes/origin/master", "refs/heads/master", "refs/remotes/origin/HEAD"]`. Note that the array is not ordered at all.
Use `getRefList` which returns an array like `["refs/remotes/origin/master", "refs/heads/master", "refs/remotes/origin/HEAD"]`. Note that the array is not ordered at all. Then run `getRef("refs/remotes/origin/HEAD")` or `setRef("refs/remotes/origin/HEAD", "0123456789abcdefghij")`.
### How can I use branches?
......
......@@ -186,6 +186,56 @@ class Repository {
.map(ref => ref.replace("refs/heads/", ""));
});
}
saveFile(path, content, base, message) {
let author, commit, parent;
return this.zeroAuth.requestAuth()
.then(auth => {
let date = new Date;
let tz = date.getTimezoneOffset() * -1;
let hours = Math.floor(Math.abs(tz / 60));
let minutes = Math.abs((tz + 60) % 60);
tz = (tz > 0 ? "+" : "-") + (hours < 10 ? "0" : "") + hours + (minutes < 10 ? "0" : "") + minutes;
author = auth.user[0].toUpperCase() + auth.user.substr(1).replace(/@.*/, "");
author += " <" + auth.user + ">";
author += " " + Math.floor(+date / 1000);
author += " " + tz;
return this.git.getBranchCommit(base);
})
.then(commitId => {
parent = commitId;
return this.git.readUnknownObject(commitId);
})
.then(commit => {
return this.git.readUnknownObject(commit.content.tree);
})
.then(base => {
return this.git.makeTreeDeltaPath(base.content, [
{
path: path,
type: "blob",
content: content
}
]);
})
.then(delta => {
return this.git.writeCommit({
tree: delta,
parents: [parent],
author: author,
committer: author,
message: message
});
})
.then(c => {
commit = c;
if(!this.git.isSha(base)) {
return this.git.setRef("refs/heads/" + base, commit);
}
})
.then(() => commit);
}
// Issues
addIssue(title, content) {
......
.files {
table-layout: auto;
width: 1024px;
margin: 0 auto;
border-spacing: 0;
border: 1px solid #DDF;
border-radius: 4px;
}
.files td {
width: auto;
margin: 0;
padding: 8px;
font-size: 16px;
}
.files tr td {
border-top: 1px solid #DDF;
}
.files tr:first-child td {
border-top: none;
}
.files-header {
background-color: #DDF;
font-family: Helvetica, Arial, sans-serif;
}
.files-header a {
color: #008;
}
.file-content, .commit-message {
padding: 0 !important;
}
.file-content-text {
display: block;
width: calc(100% - 16px);
height: 496px;
padding: 8px;
margin: 0;
border: 0;
font-family: Consolas, "Courier New", monospace;
resize: none;
}
.commit-message-input {
display: block;
width: 100%;
margin: 0;
border: 0;
border-radius: 0 0 0 4px;
}
.commit-node {
width: 0 !important;
padding: 0 !important;
border: 0 !important;
}
.commit-button {
border-radius: 0 0 4px 0;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Git Center</title>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<base href="" target="_top" id="base">
<script>base.href = document.location.href.replace("/media", "").replace("index.html", "").replace(/[&?]wrapper=False/, "").replace(/[&?]wrapper_nonce=[A-Za-z0-9]+/, "")</script>
<link rel="stylesheet" type="text/css" href="../../css/main.css">
<link rel="stylesheet" type="text/css" href="../../css/buttons.css">
<link rel="stylesheet" type="text/css" href="../../css/header.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
<link rel="stylesheet" type="text/css" href="../../hljs/default.min.css">
<link rel="stylesheet" type="text/css" href="../css/tabs.css">
<link rel="stylesheet" type="text/css" href="../css/info.css">
<link rel="stylesheet" type="text/css" href="css/file.css">
</head>
<body>
<header class="header">
<a href="../..">
<img src="../../img/logo-white.svg" class="header-logo">
<div class="header-name">Git Center</div>
</a>
<a href="../../index/">
<div class="header-item">Repository Index</div>
</a>
<a href="../../myrepos/">
<div class="header-item">My Repos</div>
</a>
<a href="../../workflow/">
<div class="header-item">Git Center workflow</div>
</a>
<a href="../../support/">
<div class="header-item">Support</div>
</a>
</header>
<main class="middle">
<h1 id="repo_name"></h1>
<a id="code_link" class="tab tab-current">
<img src="../../img/code.svg" width="16">
Code
</a>
<a id="issues_link" class="tab">
<img src="../../img/issue-open.svg" width="16">
Issues
</a>
<a id="pull_requests_link" class="tab">
<img src="../../img/pr-merged.svg" width="16">
Pull requests
</a>
<a id="settings_link" class="tab">
<img src="../../img/settings.svg" width="16">
Settings
</a>
</main>
<div class="info">
<select class="select branches" id="branches"></select>
<a class="info-link" id="permanent_link" title="Link to current tree. Data won't change if branch moves">Permanent link</a>
<a class="info-link button" id="fork">Fork</a>
<a class="info-link button button-blue" id="publish" title="Use this option after pushing">Sign &amp; Publish changes</a>
<input type="text" class="info-link input" id="git_url">
<a class="info-link button" id="view">View</a>
</div>
<table id="files" class="files">
<tr class="files-header">
<td id="files_path" colspan="2">
<span><a id="files_root">Root</a></span>
</td>
</tr>
<tr>
<td class="file-content" colspan="2">
<textarea id="file_content" class="file-content-text"></textarea>
</td>
</tr>
<tr>
<td class="commit-message">
<input type="text" class="input commit-message-input" id="commit_message" placeholder="Commit message">
</td>
<td class="commit-node">
<a class="button button-blue commit-button" id="save">Commit</a>
</td>
</tr>
</table>
<template id="edit_icon_tmpl">
<img src="../../img/edit.svg" class="edit-icon" id="edit_icon" width="16" height="16">
</template>
<script type="text/javascript" src="../../js/ZeroFrame.js"></script>
<script type="text/javascript" src="../../js/ZeroPage.js"></script>
<script type="text/javascript" src="../../js/ZeroFS.js"></script>
<script type="text/javascript" src="../../js/ZeroAuth.js"></script>
<script type="text/javascript" src="../../js/ZeroDB.js"></script>
<script type="text/javascript" src="../../js/pako.js"></script>
<script type="text/javascript" src="../../js/sha.js"></script>
<script type="text/javascript" src="../../js/git.js"></script>
<script type="text/javascript" src="../../js/repo.js"></script>
<script type="text/javascript" src="../js/path_common.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../../hljs/highlight.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
\ No newline at end of file
if(address == "1RepoXU8bQE9m7ssNwL4nnxBnZVejHCc6") {
location.href = "../../default/";
}
repo.addMerger()
.then(() => {
return repo.getContent();
})
.then(content => {
if(!content.installed) {
location.href = "../../install/?" + address;
}
showTitle(content.title);
showBranches();
showPath(true);
showLinks();
showTabs(1);
document.getElementById("view").href = "../file/?" + address + "/" + path.replace(/@/g, "@@") + "@" + branch.replace(/@/g, "@@");
return repo.getFiles(branch, "");
})
.then(() => {
// Tree exists
return repo.getFile(branch, path)
.then(blob => {
let fileContent = document.getElementById("file_content");
fileContent.value = repo.git.arrayToString(blob);
let saveButton = document.getElementById("save");
let commitMessage = document.getElementById("commit_message");
saveButton.onclick = () => {
if(saveButton.classList.contains("button-disabled")) {
return;
}
if(commitMessage.value == "") {
return;
}
saveButton.classList.add("button-disabled");
repo.saveFile(path, repo.git.stringToArray(fileContent.value), branch, commitMessage.value)
.then(commit => {
saveButton.classList.remove("button-disabled");
commitMessage.value = "";
});
};
}, () => {
// Blob doesn't exist
let fileContent = document.getElementById("file_content");
fileContent.value = "File " + path + " does not exist on branch " + branch;
document.getElementById("save").classList.add("button-disabled");
});
}, () => {
// Tree doesn't exist
let fileContent = document.getElementById("file_content");
fileContent.textContent = "Unknown branch " + branch;
document.getElementById("save").classList.add("button-disabled");
});
\ No newline at end of file
......@@ -62,6 +62,7 @@
<a class="info-link button" id="fork">Fork</a>
<a class="info-link button button-blue" id="publish" title="Use this option after pushing">Sign &amp; Publish changes</a>
<input type="text" class="info-link input" id="git_url">
<a class="info-link button" id="edit">Edit</a>
</div>
<table id="files" class="files">
......
......@@ -17,6 +17,8 @@ repo.addMerger()
showLinks();
showTabs(1);
document.getElementById("edit").href = "../edit/?" + address + "/" + path.replace(/@/g, "@@") + "@" + branch.replace(/@/g, "@@");
return repo.getFiles(branch, "");
})
.then(() => {
......
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