Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarcos committed Dec 21, 2018
2 parents f926225 + f62e1d7 commit 89ccb18
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 65 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Always reference the ticket number at the end of the issue description.

[324]: //github.com/sanoma/django-arctic/issues/324
[322]: //github.com/sanoma/django-arctic/issues/322
## pending:

### Added

- added wrappers with proper classes to blocks in base.html


## 1.3.4 (2018-11-06)
Expand Down
4 changes: 4 additions & 0 deletions arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_context_data(self, **kwargs):
context["SITE_NAME"] = self.get_site_name()
context["SITE_TITLE"] = self.get_site_title()
context["SITE_LOGO"] = self.get_site_logo()
context["SITE_FAVICON"] = self.get_site_favicon()
context["SIDEBAR_BACKGROUND"] = self.get_sidebar_background()
context["SIDEBAR_COLOR"] = self.get_sidebar_color()
context["SIDEBAR_ALT_COLOR"] = self.get_sidebar_alt_color()
Expand Down Expand Up @@ -181,6 +182,9 @@ def get_page_description(self):
def get_site_logo(self):
return arctic_setting("ARCTIC_SITE_LOGO")

def get_site_favicon(self):
return getattr(settings, "ARCTIC_SITE_FAVICON", None)

def get_site_name(self):
return arctic_setting("ARCTIC_SITE_NAME")

Expand Down
19 changes: 16 additions & 3 deletions arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def get_actions(self): # noqa: C901
view_from_url(action[1]), action[1]
)
allowed_action["modal"] = self.get_modal_link(
action[1], self
action[1], obj
)
allowed_action["type"] = "link"
allowed_action["url"] = self.in_modal(
Expand Down Expand Up @@ -675,12 +675,14 @@ def _get_field_actions(self, obj):
{
"label": field_action["label"],
"icon": field_action["icon"],
"class": field_action['class'],
"url": self.in_modal(
reverse_url(
field_action["url"], obj, self.primary_key
)
),
"modal": self.get_modal_link(field_action["url"], obj),
'attributes': field_action["attributes"]
}
)
return actions
Expand Down Expand Up @@ -711,8 +713,19 @@ def get_action_links(self):
return self._allowed_action_links

def _build_action_link(self, action_link):
icon = action_link[2] if len(action_link) == 3 else None
return {"label": action_link[0], "url": action_link[1], "icon": icon}
icon, attributes = None, None
attributes_class = generate_id('action', action_link[0])
if len(action_link) == 3:
# icon can be 3-rd arg of link or specified inside inside dict with same index
if isinstance(action_link[2], str):
icon = action_link[2]
elif isinstance(action_link[2], dict):
icon = action_link[2].get('icon_class', None)
attributes = action_link[2].get('attributes', None)
if attributes and attributes.get('class', None) and isinstance(attributes.get('class', None), list):
attributes_class = " ".join(attributes.get('class'))
return {"label": action_link[0], "url": action_link[1], 'class': attributes_class,
"icon": icon, "attributes": attributes}

def get_tool_links(self):
if not self.tool_links:
Expand Down
1 change: 1 addition & 0 deletions arctic/static/arctic/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ PATHS:
- "node_modules/selectize/dist/js/standalone/selectize.js"
- "node_modules/sortablejs/Sortable.js"
- "node_modules/iframe-resizer/js/iframeResizer.js"
- "node_modules/moment/min/moment.min.js"

# Paths to your own project code are here
- "src/assets/js/utils/helpers.js"
Expand Down
2 changes: 1 addition & 1 deletion arctic/static/arctic/dist/assets/js/app.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion arctic/static/arctic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jquery": "^3.3.1",
"jquery.are-you-sure": "^1.9.0",
"js-yaml": "^3.11.0",
"moment": "^2.22.2",
"popper.js": "^1.14.3",
"rimraf": "^2.6.2",
"sass-burger": "^1.3.1",
Expand Down Expand Up @@ -58,7 +59,8 @@
"jquery.are-you-sure.js",
"popper",
"selectize.js",
"sortablejs"
"sortablejs",
"moment.min.js"
]
},
"repository": {
Expand Down
15 changes: 12 additions & 3 deletions arctic/static/arctic/src/assets/js/components/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ function django2datepicker(django_format) {
return datepicker_format;
}

function datetimeformatter(django_date, format) {
var date_valid = moment(django_date).isValid();
if (!date_valid) {
return null;
} else {
return moment(django_date, format).toDate();
}
}


$(document).ready(function() {
$('[js-selectize]').each(function(index) {
Expand Down Expand Up @@ -118,7 +127,7 @@ $(document).ready(function() {
$.fn.datepicker.language['en'] = datetime_picker_settings;

$('[js-datepicker]').each(function(index) {
var date = new Date($(this).attr("data-date")) == 'Invalid Date' ? null : new Date($(this).attr("data-date"))
var date = datetimeformatter($(this).attr("data-date"), datetime_picker_settings.dateFormat);
var instance = this;
$(instance).attr('type', 'text');
$(instance).datepicker({
Expand All @@ -142,7 +151,7 @@ $(document).ready(function() {
});

$('[js-timepicker]').each(function(index) {
var date = new Date($(this).attr("data-time")) == 'Invalid Date' ? null : new Date($(this).attr("data-time"))
var date = datetimeformatter($(this).attr("data-time"), datetime_picker_settings.timeFormat);
var instance = this;
$(instance).attr('type', 'text');
$(instance).datepicker({
Expand All @@ -166,7 +175,7 @@ $(document).ready(function() {
});

$('[js-datetimepicker]').each(function(index) {
var date = new Date($(this).attr("data-datetime")) == 'Invalid Date' ? null : new Date($(this).attr("data-datetime"))
var date = datetimeformatter($(this).attr("data-datetime"), `${datetime_picker_settings.dateFormat} ${datetime_picker_settings.timeFormat}`);
var instance = this;
$(instance).attr('type', 'text');
$(instance).datepicker({
Expand Down
123 changes: 67 additions & 56 deletions arctic/templates/arctic/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,71 +43,82 @@ <h3 class="header__title">
</header>
{% endblock %}
<div class="content-wrapper">
{% block breadcrumbs%}
{% if breadcrumbs %}
<nav class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if forloop.last %}
<span class="breadcrumb-item active">
{{ breadcrumb.name }}
</span>
{% else %}
<a class="breadcrumb-item" href="{{ breadcrumb.url }}">
{{ breadcrumb.name }}
</a>
{% endif %}
{% endfor %}
</nav>
{% else %}
&nbsp;
{% endif %}
{% endblock %}
<div class="breadcrumb-block">
{% block breadcrumbs%}
{% if breadcrumbs %}
<nav class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if forloop.last %}
<span class="breadcrumb-item active">
{{ breadcrumb.name }}
</span>
{% else %}
<a class="breadcrumb-item" href="{{ breadcrumb.url }}">
{{ breadcrumb.name }}
</a>
{% endif %}
{% endfor %}
</nav>
{% else %}
&nbsp;
{% endif %}
{% endblock %}
</div>

{# page page description #}
{% if page_description %}
<div class="row">
<small>{{ page_description }}</small>
<div class="page-description-block">
{% block page_description %}
{% if page_description %}
<div class="row">
<small>{{ page_description }}</small>
</div>
{% endif %}
{% endblock %}
</div>
{% endif %}

{% block tabs %}
{% if tabs %}
<div class="row">
<div class="col-sm-12 col">
<ul class="nav nav-tabs" id="table-tabs" role="tablist">
{% for tab in tabs %}
<li class="nav-item">
{% if tab.active %}
<a class="nav-link active" href="javascript:">{{ tab.name }}</a></li>
{% else %}
<a class="nav-link" href="{{ tab.url }}">{{ tab.name }}</a></li>
{% endif %}
</li>
{% endfor %}
</ul>
<div class="tabs-block">
{% block tabs %}
{% if tabs %}
<div class="row">
<div class="col-sm-12 col">
<ul class="nav nav-tabs" id="table-tabs" role="tablist">
{% for tab in tabs %}
<li class="nav-item">
{% if tab.active %}
<a class="nav-link active" href="javascript:">{{ tab.name }}</a></li>
{% else %}
<a class="nav-link" href="{{ tab.url }}">{{ tab.name }}</a></li>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% endblock %}
</div>
{% endif %}
{% endblock %}

{% block messages %}
{% if messages %}
{% for message in messages %}
<div class="row">
<div class="col">
<div class="alert alert-{{ message.tags }}" data-closable>
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div class="messages-block">
{% block messages %}
{% if messages %}
{% for message in messages %}
<div class="row">
<div class="col">
<div class="alert alert-{{ message.tags }}" data-closable>
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
</div>
{% endfor %}
{% endif %}
{% endblock %}
</div>

<div class="content-block">
{% block content %}content here{% endblock %}
</div>
{% endfor %}
{% endif %}
{% endblock %}

{% block content %}content here{% endblock %}
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ <h4 class="arctic-card__title">
{% block list_actions %}
<div class="list-actions">
{% for action in row.actions %}
<a href="{{ action.url }}" class="action-{{ action.label }} btn btn-secondary btn-sm show-on-hover" title="{{ link.label|capfirst }}"
<a href="{{ action.url }}" class="{{ action.class }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
{% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
{% if action.attributes %}
{% for attr_name, attr_value in action.attributes.items %}
{{ attr_name }}="{{ attr_value }}"
{% endfor %}
{% endif %}
>
{% if action.icon %}
<i class="fa {{ action.icon }} fa-lg"></i>
Expand Down
4 changes: 4 additions & 0 deletions arctic/templates/arctic/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<meta name="description" content="">
<meta name="author" content="">

{% if SITE_FAVICON %}
<link rel="shortcut icon" href="{% static SITE_FAVICON %}"/>
{% endif %}

<title>
{% block title %}
{{ SITE_TITLE }} – {{ page_title }}
Expand Down
7 changes: 7 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ if not provided, a default color will be used.
String representing the foreground color of the sidebar, for example '#ffffff',
if not provided, a default color will be used.

## `ARCTIC_SITE_FAVICON`
The url of favicon.

## `ARCTIC_SITE_LOGO`

The url of the logo to be displayed on every page, it will also be the link to
Expand Down Expand Up @@ -316,6 +319,10 @@ standard notation by prepending a minus to the field, for example `-name`.
optional list of `('name', 'base_url', 'optional icon class')` links, that
appear on the last column of the table and can apply a certain action, such
as delete.
In case if some custom attributes required, they can be specified as last argument in form of dict. In this case
optional icon class can be provided as part of that argument dict.
Classes for action link can be specified as a list.
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'class': ['class0', 'class1'], 'custom_attr_name': 'custom_attr_value'}})`

### `get_field_actions(row)`

Expand Down

0 comments on commit 89ccb18

Please sign in to comment.