Added manual tag removal
This commit is contained in:
parent
78ccff843c
commit
005d857cfb
7 changed files with 42 additions and 3 deletions
|
@ -68,6 +68,7 @@ changeTagCategory = moderator, administrator
|
||||||
changeTagImplications = moderator, administrator
|
changeTagImplications = moderator, administrator
|
||||||
changeTagSuggestions = moderator, administrator
|
changeTagSuggestions = moderator, administrator
|
||||||
banTags = moderator, administrator
|
banTags = moderator, administrator
|
||||||
|
deleteTags = moderator, administrator
|
||||||
|
|
||||||
listComments = regularUser, powerUser, moderator, administrator
|
listComments = regularUser, powerUser, moderator, administrator
|
||||||
addComments = regularUser, powerUser, moderator, administrator
|
addComments = regularUser, powerUser, moderator, administrator
|
||||||
|
|
|
@ -45,6 +45,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
||||||
editAllComments: 'editAllComments',
|
editAllComments: 'editAllComments',
|
||||||
deleteOwnComments: 'deleteOwnComments',
|
deleteOwnComments: 'deleteOwnComments',
|
||||||
deleteAllComments: 'deleteAllComments',
|
deleteAllComments: 'deleteAllComments',
|
||||||
|
deleteTags: 'deleteTags',
|
||||||
|
|
||||||
listTags: 'listTags',
|
listTags: 'listTags',
|
||||||
massTag: 'massTag',
|
massTag: 'massTag',
|
||||||
|
|
|
@ -83,12 +83,14 @@ App.Presenters.TagPresenter = function(
|
||||||
tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')),
|
tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')),
|
||||||
}));
|
}));
|
||||||
$el.find('.post-list').hide();
|
$el.find('.post-list').hide();
|
||||||
$el.find('form').submit(editFormSubmitted);
|
$el.find('form').submit(function(e) { e.preventDefault(); });
|
||||||
|
$el.find('form button[name=update]').click(updateButtonClicked);
|
||||||
|
$el.find('form button[name=delete]').click(deleteButtonClicked);
|
||||||
implicationsTagInput = App.Controls.TagInput($el.find('[name=implications]'));
|
implicationsTagInput = App.Controls.TagInput($el.find('[name=implications]'));
|
||||||
suggestionsTagInput = App.Controls.TagInput($el.find('[name=suggestions]'));
|
suggestionsTagInput = App.Controls.TagInput($el.find('[name=suggestions]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function editFormSubmitted(e) {
|
function updateButtonClicked(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $form = $el.find('form');
|
var $form = $el.find('form');
|
||||||
var formData = {};
|
var formData = {};
|
||||||
|
@ -121,6 +123,18 @@ App.Presenters.TagPresenter = function(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteButtonClicked(e) {
|
||||||
|
if (!window.confirm('Are you sure you want to delete this tag?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
promise.wait(api.delete('/tags/' + tag.name))
|
||||||
|
.then(function(response) {
|
||||||
|
router.navigate('#/tags');
|
||||||
|
}).fail(function(response) {
|
||||||
|
window.alert(response.json && response.json.error || 'An error occured.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function renderPosts(posts) {
|
function renderPosts(posts) {
|
||||||
var $target = $el.find('.post-list ul');
|
var $target = $el.find('.post-list ul');
|
||||||
_.each(posts, function(post) {
|
_.each(posts, function(post) {
|
||||||
|
|
|
@ -70,7 +70,8 @@
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label class="form-label"></label>
|
<label class="form-label"></label>
|
||||||
<div class="form-input">
|
<div class="form-input">
|
||||||
<button type="submit">Update</button>
|
<button type="submit" name="update">Update</button>
|
||||||
|
<button type="submit" name="delete">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -37,6 +37,7 @@ final class TagController extends AbstractController
|
||||||
$router->get('/api/tags/:tagName', [$this, 'getTag']);
|
$router->get('/api/tags/:tagName', [$this, 'getTag']);
|
||||||
$router->get('/api/tags/:tagName/siblings', [$this, 'getTagSiblings']);
|
$router->get('/api/tags/:tagName/siblings', [$this, 'getTagSiblings']);
|
||||||
$router->put('/api/tags/:tagName', [$this, 'updateTag']);
|
$router->put('/api/tags/:tagName', [$this, 'updateTag']);
|
||||||
|
$router->delete('/api/tags/:tagName', [$this, 'deleteTag']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTag($tagName)
|
public function getTag($tagName)
|
||||||
|
@ -97,6 +98,13 @@ final class TagController extends AbstractController
|
||||||
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
return $this->tagViewProxy->fromEntity($tag, $this->getFullFetchConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteTag($tagName)
|
||||||
|
{
|
||||||
|
$tag = $this->tagService->getByName($tagName);
|
||||||
|
$this->privilegeService->assertPrivilege(Privilege::DELETE_TAGS);
|
||||||
|
return $this->tagService->deleteTag($tag);
|
||||||
|
}
|
||||||
|
|
||||||
private function getFullFetchConfig()
|
private function getFullFetchConfig()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
|
@ -46,6 +46,7 @@ class Privilege
|
||||||
const CHANGE_TAG_IMPLICATIONS = 'changeTagImplications';
|
const CHANGE_TAG_IMPLICATIONS = 'changeTagImplications';
|
||||||
const CHANGE_TAG_SUGGESTIONS = 'changeTagSuggestions';
|
const CHANGE_TAG_SUGGESTIONS = 'changeTagSuggestions';
|
||||||
const BAN_TAGS = 'banTags';
|
const BAN_TAGS = 'banTags';
|
||||||
|
const DELETE_TAGS = 'deleteTags';
|
||||||
|
|
||||||
const LIST_COMMENTS = 'listComments';
|
const LIST_COMMENTS = 'listComments';
|
||||||
const ADD_COMMENTS = 'addComments';
|
const ADD_COMMENTS = 'addComments';
|
||||||
|
|
|
@ -165,6 +165,19 @@ class TagService
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteTag(Tag $tag)
|
||||||
|
{
|
||||||
|
if ($tag->getUsages() !== 0)
|
||||||
|
throw new \DomainException('Only tags with no usages can be deleted.');
|
||||||
|
|
||||||
|
$transactionFunc = function() use ($tag)
|
||||||
|
{
|
||||||
|
$this->tagDao->deleteById($tag->getId());
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->transactionManager->commit($transactionFunc);
|
||||||
|
}
|
||||||
|
|
||||||
private function updateTagName(Tag $tag, $newName)
|
private function updateTagName(Tag $tag, $newName)
|
||||||
{
|
{
|
||||||
$otherTag = $this->tagDao->findByName($newName);
|
$otherTag = $this->tagDao->findByName($newName);
|
||||||
|
|
Loading…
Reference in a new issue