Commit 244a2b2f authored by Ivanq's avatar Ivanq

Show and edit indexation on 'Settings' tab

parent 0c3c874a
......@@ -498,15 +498,26 @@ class Repository {
});
}
isInIndex() {
// 0 - not indexed
// 1 - indexed
// 2 - indexed by current user
// 0b01
// ^^ indexed by somebody else
// | indexed by you
return this.zeroDB.query("SELECT repo_index.*, json.cert_user_id FROM repo_index, json WHERE repo_index.json_id = json.json_id AND repo_index.address = :address", {
address: this.address
})
.then(addresses => {
let auth = this.zeroAuth.getAuth();
return (auth && addresses.length == 1 && addresses[0].cert_user_id == auth.user) ? 2 : addresses.length > 0 ? 1 : 0;
let indexedByYou = auth && addresses.some(address => address.cert_user_id == auth.user);
let indexedBySomebody = addresses.length > (indexedByYou ? 1 : 0);
return (indexedByYou << 1) | indexedBySomebody;
});
}
getIndexers() {
return this.zeroDB.query("SELECT repo_index.*, json.cert_user_id FROM repo_index, json WHERE repo_index.json_id = json.json_id AND repo_index.address = :address", {
address: this.address
})
.then(addresses => {
return addresses.map(address => address.cert_user_id);
});
}
......
......@@ -31,4 +31,18 @@
vertical-align: top;
background-color: #888;
}
.indexation-table {
display: inline-table;
vertical-align: top;
border: 1px solid #888;
border-collapse: collapse;
}
.indexation-table tbody, .indexation-table tr, .indexation-table td {
border: inherit;
}
.indexation-table td {
padding: 6px;
}
\ No newline at end of file
......@@ -51,12 +51,20 @@
</div>
<div class="entry">
<div class="entry-title">Visibility</div>
<div class="entry-title">Indexation</div>
<div class="entry-value">
<select class="select">
<option>Visible (the repository is listed in index)</option>
<option>Hidden (the repository is not listed, but accessable by link)</option>
</select>
<table id="indexation_table" class="indexation-table">
<tr>
<td>
<img id="indexation_you" height="16">
</td>
<td>
<img id="indexation_other" height="16">
</td>
</tr>
</table>
<a id="indexation_index" class="button entry-value-margin">Index</a>
<a id="indexation_unindex" class="button entry-value-margin">Unindex</a>
</div>
</div>
......
let indexation;
function showIndexation() {
document.getElementById("indexation_you").src = indexation & 2 ? "../../img/tick.svg" : "../../img/cross.svg";
document.getElementById("indexation_you").title = "The repository is" + (indexation & 2 ? " " : " not ") + "indexed by you";
document.getElementById("indexation_other").src = indexation & 1 ? "../../img/tick.svg" : "../../img/cross.svg";
document.getElementById("indexation_other").title = "The repository is" + (indexation & 1 ? " " : " not ") + "indexed by somebody else";
}
repo.addMerger()
.then(() => {
return repo.getContent();
......@@ -6,6 +15,70 @@ repo.addMerger()
showTitle(content.title);
showTabs(1);
// Load indexation
return repo.isInIndex();
})
.then(i => {
indexation = i;
showIndexation();
let index = document.getElementById("indexation_index");
index.onclick = () => {
if(index.classList.contains("button-disabled")) {
return;
}
if(indexation & 2) {
zeroPage.alert("You cannot index a repo which is already indexed by you");
} else {
index.classList.add("button-disabled");
unindex.classList.add("button-disabled");
repo.addToIndex()
.then(() => {
indexation |= 2;
zeroPage.alert("The repo was added to your index");
showIndexation();
index.classList.remove("button-disabled");
unindex.classList.remove("button-disabled");
});
}
};
let unindex = document.getElementById("indexation_unindex");
unindex.onclick = () => {
if(unindex.classList.contains("button-disabled")) {
return;
}
if(indexation & 2) {
index.classList.add("button-disabled");
unindex.classList.add("button-disabled");
repo.removeFromIndex()
.then(indexers => {
if(indexers) {
indexation = 1;
zeroPage.alert("The repo was removed from your index but not from " + indexers.map(indexer => "<b>" + indexer + "</b>").join(", ") + " index(es)");
} else {
indexation = 0;
zeroPage.alert("The repo was completely removed from index");
}
showIndexation();
index.classList.remove("button-disabled");
unindex.classList.remove("button-disabled");
});
} else {
if(indexation & 1) {
zeroPage.alert("You cannot unindex a repo which is indexed by somebody else");
} else {
zeroPage.alert("You cannot unindex a repo which is not indexed at all");
}
}
};
return repo.getMaintainers();
})
.then(maintainers => {
......
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