# Path: core/models.py
# class Board(models.Model):
# 
#     name = models.CharField(max_length=100)
#     webhook_activate = models.BooleanField(default=False)
#     trello_board_id = models.CharField(max_length=100)
#     trello_token = models.CharField(max_length=100)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "boards"
# 
#     def __str__(self):
#         return self.name
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Webhook(models.Model):
# 
#     name = models.CharField(max_length=50)
#     incoming_webhook_url = models.CharField(max_length=300, unique=True)
# 
#     icon_url = models.CharField(
#         max_length=250,
#         default="http://maffrigby.com/wp-content/uploads/2015/05/trello-icon.png",
#     )
#     username = models.CharField(max_length=30, default="Matterllo")
# 
#     board = models.ManyToManyField(Board)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "webhooks"
# 
#     def __str__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
#     def __unicode__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
# class Bridge(models.Model):
#     EVENT_CHOICES = (
#         # card
#         ("addAttachmentToCard", "addAttachmentToCard"),
#         ("addLabelToCard", "addLabelToCard"),
#         ("addMemberToCard", "addMemberToCard"),
#         ("commentCard", "commentCard"),
#         ("copyCard", "copyCard"),
#         ("createCard", "createCard"),
#         ("emailCard", "emailCard"),
#         ("moveCardFromBoard", "moveCardFromBoard"),
#         ("moveCardToBoard", "moveCardToBoard"),
#         ("removeLabelFromCard", "removeLabelFromCard"),
#         ("removeMemberFromCard", "removeMemberFromCard"),
#         (
#             "updateCard",
#             "updateCard (include moveCardToList, renameCard, renameCardDesc, updateCardDueDate, removeCardDueDate, archiveCard, unarchiveCard)",
#         ),
#         # checklist
#         ("addChecklistToCard", "addChecklistToCard"),
#         ("createCheckItem", "createCheckItem"),
#         ("updateCheckItemStateOnCard", "updateCheckItemStateOnCard"),
#         # list
#         ("archiveList", "archiveList"),
#         ("createList", "createList"),
#         ("moveListFromBoard", "moveCardFromBoard"),
#         ("moveListToBoard", "moveListToBoard"),
#         ("renameList", "renameList"),
#         ("updateList", "updateList"),
#     )
# 
#     webhook = models.ForeignKey(Webhook, on_delete=models.CASCADE)
#     board = models.ForeignKey(Board, on_delete=models.CASCADE)
# 
#     events = models.CharField(max_length=700)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name_plural = "bridges"
# 
#     def __str__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def __unicode__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def events_as_list(self):
#         return literal_eval(self.events)
# 
# Path: core/forms.py
# class BridgeCreateForm(forms.ModelForm):
#     events = forms.MultipleChoiceField(
#         choices=Bridge.EVENT_CHOICES,
#         widget=forms.CheckboxSelectMultiple,
#     )
# 
#     def __init__(self, *args, **kwargs):
#         super(BridgeCreateForm, self).__init__(*args, **kwargs)
#         helper = self.helper = FormHelper()
# 
#         layout = helper.layout = Layout()
#         layout.append(Field("events", css_class="board-event"))
#         layout.append(
#             FormActions(
#                 HTML(
#                     '<button class="btn btn-info" type="button" onclick="document.querySelectorAll(\'.board-event\').forEach(x => x.checked = true);">Check all</button>'
#                 )
#             )
#         )
#         layout.append(
#             FormActions(
#                 HTML(
#                     '<button class="btn btn-info" type="button" onclick="document.querySelectorAll(\'.board-event\').forEach(x => x.checked = false);">Uncheck all</button>'
#                 )
#             )
#         )
#         layout.append(FormActions(Submit("save", "Save")))
# 
#         helper.form_show_labels = False
#         helper.form_class = "form-horizontal"
#         helper.field_class = "col-lg-8"
#         helper.help_text_inline = True
# 
#     class Meta:
#         model = Bridge
#         fields = ["events"]
#         help_texts = {
#             "events": 'The generated key from <a href="https://docs.mattermost.com/developer/webhooks-incoming.html#setting-up-existing-integrations">Mattermost webhook</a>.',
#         }


from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic import ListView
from django.views.generic.edit import CreateView
from django.views.generic.detail import DetailView
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from core.models import Board, Webhook, Bridge
from core.forms import BridgeCreateForm
# -*- coding: utf-8 -*-



class BridgeListView(ListView):
    model = Bridge
    template_name = "core/index.html"


class BridgeDetailView(DetailView):
    model = Bridge


class BridgeCreateView(SuccessMessageMixin, CreateView):
    model = Bridge

# Path: core/models.py
# class Board(models.Model):
# 
#     name = models.CharField(max_length=100)
#     webhook_activate = models.BooleanField(default=False)
#     trello_board_id = models.CharField(max_length=100)
#     trello_token = models.CharField(max_length=100)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "boards"
# 
#     def __str__(self):
#         return self.name
# 
#     def __unicode__(self):
#         return "{}".format(self.name)
# 
# class Webhook(models.Model):
# 
#     name = models.CharField(max_length=50)
#     incoming_webhook_url = models.CharField(max_length=300, unique=True)
# 
#     icon_url = models.CharField(
#         max_length=250,
#         default="http://maffrigby.com/wp-content/uploads/2015/05/trello-icon.png",
#     )
#     username = models.CharField(max_length=30, default="Matterllo")
# 
#     board = models.ManyToManyField(Board)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         ordering = ["name"]
#         verbose_name_plural = "webhooks"
# 
#     def __str__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
#     def __unicode__(self):
#         return "{} :: {}".format(self.name, self.incoming_webhook_url)
# 
# class Bridge(models.Model):
#     EVENT_CHOICES = (
#         # card
#         ("addAttachmentToCard", "addAttachmentToCard"),
#         ("addLabelToCard", "addLabelToCard"),
#         ("addMemberToCard", "addMemberToCard"),
#         ("commentCard", "commentCard"),
#         ("copyCard", "copyCard"),
#         ("createCard", "createCard"),
#         ("emailCard", "emailCard"),
#         ("moveCardFromBoard", "moveCardFromBoard"),
#         ("moveCardToBoard", "moveCardToBoard"),
#         ("removeLabelFromCard", "removeLabelFromCard"),
#         ("removeMemberFromCard", "removeMemberFromCard"),
#         (
#             "updateCard",
#             "updateCard (include moveCardToList, renameCard, renameCardDesc, updateCardDueDate, removeCardDueDate, archiveCard, unarchiveCard)",
#         ),
#         # checklist
#         ("addChecklistToCard", "addChecklistToCard"),
#         ("createCheckItem", "createCheckItem"),
#         ("updateCheckItemStateOnCard", "updateCheckItemStateOnCard"),
#         # list
#         ("archiveList", "archiveList"),
#         ("createList", "createList"),
#         ("moveListFromBoard", "moveCardFromBoard"),
#         ("moveListToBoard", "moveListToBoard"),
#         ("renameList", "renameList"),
#         ("updateList", "updateList"),
#     )
# 
#     webhook = models.ForeignKey(Webhook, on_delete=models.CASCADE)
#     board = models.ForeignKey(Board, on_delete=models.CASCADE)
# 
#     events = models.CharField(max_length=700)
# 
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name_plural = "bridges"
# 
#     def __str__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def __unicode__(self):
#         return "{}::{}".format(self.board, self.webhook)
# 
#     def events_as_list(self):
#         return literal_eval(self.events)
# 
# Path: core/forms.py
# class BridgeCreateForm(forms.ModelForm):
#     events = forms.MultipleChoiceField(
#         choices=Bridge.EVENT_CHOICES,
#         widget=forms.CheckboxSelectMultiple,
#     )
# 
#     def __init__(self, *args, **kwargs):
#         super(BridgeCreateForm, self).__init__(*args, **kwargs)
#         helper = self.helper = FormHelper()
# 
#         layout = helper.layout = Layout()
#         layout.append(Field("events", css_class="board-event"))
#         layout.append(
#             FormActions(
#                 HTML(
#                     '<button class="btn btn-info" type="button" onclick="document.querySelectorAll(\'.board-event\').forEach(x => x.checked = true);">Check all</button>'
#                 )
#             )
#         )
#         layout.append(
#             FormActions(
#                 HTML(
#                     '<button class="btn btn-info" type="button" onclick="document.querySelectorAll(\'.board-event\').forEach(x => x.checked = false);">Uncheck all</button>'
#                 )
#             )
#         )
#         layout.append(FormActions(Submit("save", "Save")))
# 
#         helper.form_show_labels = False
#         helper.form_class = "form-horizontal"
#         helper.field_class = "col-lg-8"
#         helper.help_text_inline = True
# 
#     class Meta:
#         model = Bridge
#         fields = ["events"]
#         help_texts = {
#             "events": 'The generated key from <a href="https://docs.mattermost.com/developer/webhooks-incoming.html#setting-up-existing-integrations">Mattermost webhook</a>.',
#         }


# Path: core/views/bridge.py
from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic import ListView
from django.views.generic.edit import CreateView
from django.views.generic.detail import DetailView
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from core.models import Board, Webhook, Bridge
from core.forms import BridgeCreateForm

# -*- coding: utf-8 -*-



class BridgeListView(ListView):
    model = Bridge
    template_name = "core/index.html"


class BridgeDetailView(DetailView):
    model = Bridge


class BridgeCreateView(SuccessMessageMixin, CreateView):
    model = Bridge

    form_class = BridgeCreateForm