-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61e3a69
commit f50e6a8
Showing
13 changed files
with
305 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("common", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="LinkType", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("order", models.PositiveIntegerField(db_index=True, editable=False, verbose_name="order")), | ||
("name", models.CharField(max_length=200, unique=True, verbose_name="nombre")), | ||
], | ||
options={ | ||
"verbose_name": "tipo de enlace", | ||
"verbose_name_plural": "tipos de enlace", | ||
"ordering": ("order",), | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Link", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("order", models.PositiveIntegerField(db_index=True, editable=False, verbose_name="order")), | ||
("name", models.CharField(max_length=2000, unique=True, verbose_name="nombre")), | ||
( | ||
"icon", | ||
models.CharField( | ||
help_text="<a href='https://materialdesignicons.com/' target='_blank'>Material Design Icons</a>", | ||
max_length=50, | ||
verbose_name="icono en la aplicación", | ||
), | ||
), | ||
("url", models.CharField(max_length=2000, unique=True, verbose_name="url")), | ||
( | ||
"type", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="links", | ||
to="common.linktype", | ||
verbose_name="tipo", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "enlace", | ||
"verbose_name_plural": "enlaces", | ||
"ordering": ("order",), | ||
"abstract": False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from ordered_model.models import OrderedModel as Orderable | ||
|
||
|
||
class LinkType(Orderable, models.Model): | ||
name = models.CharField(_("nombre"), max_length=200, blank=False, unique=True) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta(Orderable.Meta): | ||
verbose_name = _("tipo de enlace") | ||
verbose_name_plural = _("tipos de enlace") | ||
|
||
|
||
class Link(Orderable, models.Model): | ||
name = models.CharField(_("nombre"), max_length=2000, blank=False, unique=True) | ||
icon = models.CharField( | ||
_("icono en la aplicación"), | ||
help_text="<a href='https://materialdesignicons.com/' target='_blank'>Material Design Icons</a>", | ||
max_length=50, | ||
blank=False, | ||
) | ||
url = models.CharField(_("url"), max_length=2000, blank=False, unique=True) | ||
type = models.ForeignKey( | ||
LinkType, verbose_name=_("tipo"), related_name="links", blank=False, null=False, on_delete=models.PROTECT, | ||
) | ||
|
||
order_with_respect_to = ("type",) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta(Orderable.Meta): | ||
verbose_name = _("enlace") | ||
verbose_name_plural = _("enlaces") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from import_export import resources | ||
from import_export.fields import Field | ||
from import_export.widgets import ForeignKeyWidget | ||
from taggit.models import Tag | ||
|
||
from .models import Link, LinkType | ||
|
||
|
||
class LinkResource(resources.ModelResource): | ||
type = Field(attribute="type", widget=ForeignKeyWidget(model=LinkType, field="name"), readonly=False) | ||
|
||
class Meta: | ||
model = Link | ||
fields = ("id", "name", "icon", "url", "type", "order") | ||
export_order = fields | ||
|
||
|
||
class LinkTypeResource(resources.ModelResource): | ||
class Meta: | ||
model = LinkType | ||
fields = ("id", "name", "order") | ||
export_order = fields | ||
|
||
|
||
class TagResource(resources.ModelResource): | ||
class Meta: | ||
model = Tag | ||
fields = ("id", "name", "slug") | ||
export_order = fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<template> | ||
<v-menu | ||
v-model="showMenu" | ||
content-class="v-dialog--scrollable" | ||
:min-width="400" | ||
:max-width="400" | ||
:close-on-content-click="false" | ||
:nudge-width="200" | ||
bottom | ||
left | ||
offset-y | ||
> | ||
<template #activator="{ on: menu }"> | ||
<v-tooltip bottom> | ||
<template #activator="{ on: tooltip }"> | ||
<v-btn v-show="$vuetify.breakpoint.smAndUp" :disabled="loading" icon v-on="{ ...tooltip, ...menu }"> | ||
<v-icon>mdi-apps</v-icon> | ||
</v-btn> | ||
</template> | ||
<span> Enlaces </span> | ||
</v-tooltip> | ||
</template> | ||
|
||
<v-card> | ||
<v-card-text> | ||
<template v-for="(links, type, index) in itemsByType"> | ||
<v-divider v-if="index" :key="`${type}-divider`" class="my-2"></v-divider> | ||
<v-row :key="type" dense> | ||
<v-col v-for="link in links" :key="link.name" cols="4"> | ||
<v-hover v-slot="{ hover }"> | ||
<v-card :href="link.url" target="_blank" class="pa-2" flat ripple> | ||
<div class="d-flex justify-center"> | ||
<v-icon x-large :color="hover ? 'secondary' : 'default'">{{ link.icon }}</v-icon> | ||
</div> | ||
<div class="d-flex justify-center text-center"> | ||
<span :class="`${hover ? 'secondary' : 'default'}--text text-truncate`"> | ||
{{ link.name }} | ||
</span> | ||
</div> | ||
</v-card> | ||
</v-hover> | ||
</v-col> | ||
</v-row> | ||
</template> | ||
</v-card-text> | ||
</v-card> | ||
</v-menu> | ||
</template> | ||
|
||
<script> | ||
import { groupBy } from "lodash"; | ||
import LinkService from "@/services/common/link-service"; | ||
export default { | ||
name: "LinkManager", | ||
data() { | ||
return { | ||
showMenu: false, | ||
loading: false, | ||
items: [], | ||
}; | ||
}, | ||
computed: { | ||
itemsByType() { | ||
return groupBy(this.items, "type.order"); | ||
}, | ||
}, | ||
created() { | ||
this.fetchItems(); | ||
}, | ||
methods: { | ||
async fetchItems() { | ||
try { | ||
this.loading = true; | ||
const response = await LinkService.list({ expand: "type" }); | ||
this.items = response.data; | ||
} finally { | ||
this.loading = false; | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.v-dialog--scrollable { | ||
max-height: 80%; | ||
} | ||
</style> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { keyBy } from "lodash"; | ||
|
||
import LinkService from "./link-service"; | ||
import NotificationService from "./notification-service"; | ||
import TagService from "./tag-service"; | ||
|
||
const services = keyBy([NotificationService, TagService], "baseUrlName"); | ||
const services = keyBy([LinkService, NotificationService, TagService], "baseUrlName"); | ||
|
||
export default services; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import BaseService from "../base-service"; | ||
|
||
class LinkService extends BaseService { | ||
baseUrlName = "common:link"; | ||
} | ||
|
||
const service = Object.freeze(new LinkService()); | ||
|
||
export default service; |