Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions taccsite_cms/contrib/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Get Django `models.CharField` `choices`
def get_choices(choice_dict):
"""Get a sequence for a Django model field choices from a dictionary.
:param Dict[str, Dict[str, str]] dictionary: choice as key for dictionary of classnames and descriptions
:return: a sequence for django.db.models.CharField.choices
:rtype: List[Tuple[str, str], ...]
"""
choices = []

for key, data in choice_dict.items():
choice = (key, data['description'])
choices.append(choice)

return choices



# GH-93, GH-142, GH-133: Upcoming functions here (ease merge conflict, maybe)



# Concatenate a list of CSS classes
# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/master/djangocms_bootstrap4/helpers.py
def concat_classnames(classes):
"""Concatenate a list of classname strings (without failing on None)"""
# SEE: https://stackoverflow.com/a/20271297/11817077
return ' '.join(_class for _class in classes if _class)



# GH-93, GH-142, GH-133: Upcoming functions here (ease merge conflict, maybe)
12 changes: 12 additions & 0 deletions taccsite_cms/contrib/taccsite_system_monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# System Monitor

This is a _minimal_ conversion of the Frontera Sysmon snippet to a Django CMS plugin.

> There is a functionally more advanced plugin, [bitbucket:rochaa/tacc-sysmon](https://bitbucket.org/rochaa/tacc-sysmon), which allows:
>
> - server-side requests (Python) instead of client-side requests (JavaScript)
> - multi-system tables

## To Do

- [GH-295](https://github.com/TACC/Core-CMS/issues/295)
Empty file.
52 changes: 52 additions & 0 deletions taccsite_cms/contrib/taccsite_system_monitor/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _

from taccsite_cms.contrib.helpers import concat_classnames

from .models import TaccsiteSystemMonitor

@plugin_pool.register_plugin
class TaccsiteSystemMonitorPlugin(CMSPluginBase):
"""
Components > "System Monitor" Plugin
https://url.to/docs/components/system_monitor/
"""
module = 'TACC Site'
model = TaccsiteSystemMonitor
name = _('System Monitor')
render_template = 'system_monitor.html'

cache = True
text_enabled = False
allow_children = False

fieldsets = [
(_('Single System'), {
# NOTE: Can GH-295 fix the reload caveat?
'description': 'Only a single system may be shown. After editing this plugin, reload the page to load system data.',
'fields': (
'system',
)
}),
(_('Advanced settings'), {
'classes': ('collapse',),
'fields': (
'attributes',
)
}),
]

# Render

def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
request = context['request']

classes = concat_classnames([
's-system-monitor',
instance.attributes.get('class'),
])
instance.attributes['class'] = classes

return context
1 change: 1 addition & 0 deletions taccsite_cms/contrib/taccsite_system_monitor/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULT_SYSTEM = 'frontera.tacc.utexas.edu'
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.2.16 on 2021-08-16 19:42

from django.db import migrations, models
import django.db.models.deletion
import djangocms_attributes_field.fields


class Migration(migrations.Migration):

initial = True

dependencies = [
('cms', '0022_auto_20180620_1551'),
]

operations = [
migrations.CreateModel(
name='TaccsiteSystemMonitor',
fields=[
('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_system_monitor_taccsitesystemmonitor', serialize=False, to='cms.CMSPlugin')),
('system', models.CharField(choices=[('frontera.tacc.utexas.edu', 'Frontera'), ('stampede2.tacc.utexas.edu', 'Stampede2'), ('maverick2.tacc.utexas.edu', 'Maverick2'), ('longhorn.tacc.utexas.edu', 'Longhorn')], default='frontera.tacc.utexas.edu', max_length=255, verbose_name='System')),
('attributes', djangocms_attributes_field.fields.AttributesField(default=dict)),
],
options={
'abstract': False,
},
bases=('cms.cmsplugin',),
),
]
Empty file.
45 changes: 45 additions & 0 deletions taccsite_cms/contrib/taccsite_system_monitor/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from cms.models.pluginmodel import CMSPlugin
from django.utils.translation import gettext_lazy as _

from django.db import models

from djangocms_attributes_field import fields

from taccsite_cms.contrib.helpers import get_choices

from .constants import DEFAULT_SYSTEM

# TODO: (Maybe in GH-295) Do not replicate `display_name` data from API
SYSTEM_DICT = {
'frontera.tacc.utexas.edu': {
'description': 'Frontera'
},
'stampede2.tacc.utexas.edu': {
'description': 'Stampede2'
},
'maverick2.tacc.utexas.edu': {
'description': 'Maverick2'
},
'longhorn.tacc.utexas.edu': {
'description': 'Longhorn'
},
}
SYSTEM_CHOICES = get_choices(SYSTEM_DICT)

class TaccsiteSystemMonitor(CMSPlugin):
"""
Components > "System Monitor" Model
"""
system = models.CharField(
verbose_name=_('System'),
choices=SYSTEM_CHOICES,
blank=False,
max_length=255,
default=DEFAULT_SYSTEM,
)

attributes = fields.AttributesField()

def get_short_description(self):
system_choice = SYSTEM_DICT[self.system]
return system_choice['description']
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
System Monitor a.k.a. SysMon

Styles for the system monitor table that assumes external code:

- custom properties
(for `--global-...`)
- Bootstrap
(for badge)
- Iconworks
(for icon)

Styleguide Trumps.Scopes.SystemMonitor
*/

/* Container */

.s-system-monitor {
font-size: 1.4rem;
min-width: 320px;
}

/* Table */

.s-system-monitor table {
/* vert. `padding` + vert. `border-spacing` + `border-width` = 14px */
padding: 6px 0;

border: 1px solid var(--global-color-primary--xx-light);
border-radius: 9px;
border-spacing: 14px 7px; /* Overwrite Bootstrap 3 */
border-collapse: separate; /* Overwrite Bootstrap 4 */
}
.s-system-monitor thead > tr {
margin-left: 5px;
margin-right: 5px;
}
.s-system-monitor th {
font-weight: var(--bold);
}
.s-system-monitor td {
font-weight: var(--medium);
}

/* Overwrite Bootstrap Class */
.s-system-monitor .table {
margin-bottom: 0px;
}
.s-system-monitor .table-dark {
color: var(--global-color-primary--normal);
background-color: var(--global-color-primary--xx-dark);
}
.s-system-monitor .table thead th {
border-bottom: 1px solid var(--global-color-primary--dark);
}
.s-system-monitor .table th,
.s-system-monitor .table td {
vertical-align: middle;
border: none;
padding: 0 0 5px;
}
.s-system-monitor .table td {
padding: 0;
}

/* Status Label */

.s-system-monitor .badge {
font-family: Roboto;
}

/* Overwrite Bootstrap */
.s-system-monitor .badge {
border-radius: 3px;
font-size: 1.3rem;
font-weight: normal;
}

/* Overwrite IconWorks */
.s-system-monitor .iconworks:before {
padding-right: 0.5em;
}
Loading