Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAMBRO Home Page Update (index.html) #1100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions modules/templates/SAMBRO/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def onaccept(form):
s3db.msg_parser_enable(_id)

async = current.s3task.async

# Poll
async("msg_poll", args=["msg_rss_channel", channel_id])

Expand Down
123 changes: 100 additions & 23 deletions modules/templates/SAMBRO/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,63 @@
import simplejson as json # try external module
except:
import gluon.contrib.simplejson as json # fallback to pure-Python module

from gluon import current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid such whitespace changes - the existing style was the one used in all the other code

from gluon.html import *
from gluon.storage import Storage

from s3 import S3LocationFilter, S3OptionsFilter, S3FilterForm, S3CustomController

THEME = "CAP"
THEME = "SAMBRO"

# =============================================================================
class index(S3CustomController):
""" Custom Home Page """

def __call__(self):
response = current.response
s3 = response.s3
T = current.T

map = current.gis.show_map()

output = {}
output["map"] = map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are right after one another then slightly more efficient to do the 2 together:
output = dict(map=map)


# Image Carousel
# Latest 4 Events and Alerts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in the code you're copying from, these are both just types of cms_post, yet in SAMBRO an alert should be a cap_alert, no?
Does SAMBRO need Events at all?

from s3.s3query import FS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally prefer to just import from the main s3 module (this may have been wrong in the code you copy/pasted)

s3db = current.s3db
layout = s3.render_posts
list_id = "news_datalist"
limit = 4
list_fields = ["series_id",
"location_id",
"date",
"body",
"created_by",
"created_by$organisation_id",
"document.file",
"event_post.event_id",
]

resource = s3db.resource("cms_post")
resource.add_filter(FS("series_id$name") == "Event")
# Only show Future Events
resource.add_filter(resource.table.date >= current.request.now)
# Order with next Event first
orderby = "date"
output["events"] = latest_records(resource, layout, list_id, limit, list_fields, orderby)

resource = s3db.resource("cms_post")
resource.add_filter(FS("series_id$name") == "Alert")
# Order with most recent Alert first
orderby = "date desc"
output["alerts"] = latest_records(resource, layout, list_id, limit, list_fields, orderby)


self._view(THEME, "index.html")

return output

# =============================================================================
class subscriptions(S3CustomController):
Expand All @@ -37,8 +86,7 @@ def __call__(self):
# Available resources
resources = [dict(resource="cap_alert",
url="cap/alert",
label=T("Updates")),
]
label=T("Updates")),]

# Filter widgets
# @note: subscription manager has no resource context, so
Expand All @@ -49,23 +97,19 @@ def __call__(self):
options = s3db.cap_info_category_opts,
represent = "%(name)s",
resource = "cap_info",
_name = "category-filter",
),
_name = "category-filter",),
S3LocationFilter("location_id",
label = T("Location(s)"),
levels = ("L0",),
resource = "cap_area_location",
options = gis.get_countries().keys(),
_name = "location-filter",
),
_name = "location-filter",),
S3OptionsFilter("language",
label = T("Language"),
options = settings.get_cap_languages(),
represent = "%(name)s",
resource = "cap_info",
_name = "language-filter",
),
]
_name = "language-filter",),]

# Title and view
title = T("Notification Settings")
Expand All @@ -91,20 +135,16 @@ def _manage_subscriptions(self, resources, filters):

# L10n
T = current.T
labels = Storage(
RESOURCES = T("Subscribe To"),
labels = Storage(RESOURCES = T("Subscribe To"),
NOTIFY_ON = T("Notify On"),
FREQUENCY = T("Frequency"),
NOTIFY_BY = T("Notify By"),
MORE = T("More Options"),
LESS = T("Less Options"),
)
messages = Storage(
ERROR = T("Error: could not update notification settings"),
SUCCESS = T("Notification settings updated"),
)

# Get current subscription settings resp. form defaults
LESS = T("Less Options"),)
messages = Storage(ERROR = T("Error: could not update notification settings"),
SUCCESS = T("Notification settings updated"),)

# Get current subscription settings resp. form defaults
subscription = self._get_subscription()

# Formstyle bootstrap
Expand Down Expand Up @@ -320,8 +360,7 @@ def _update_subscription(self, subscription):
method=subscription["method"])
subscription_id = success
else:
success = db(stable.id == subscription_id).update(
pe_id=pe_id,
success = db(stable.id == subscription_id).update(pe_id=pe_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to tweak all this whitespace then please sort indents

filter_id=filter_id,
notify_on=subscription["notify_on"],
frequency=frequency,
Expand Down Expand Up @@ -397,4 +436,42 @@ def _update_subscription(self, subscription):
subscription["filter_id"] = filter_id
return subscription

# =============================================================================
def latest_records(resource, layout, list_id, limit, list_fields, orderby):
"""
Display a dataList of the latest records for a resource
@todo: remove this wrapper
"""

#orderby = resource.table[orderby]
datalist, numrows, ids = resource.datalist(fields=list_fields,
start=None,
limit=limit,
list_id=list_id,
orderby=orderby,
layout=layout)
if numrows == 0:
# Empty table or just no match?
from s3.s3crud import S3CRUD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from s3 import S3CRUD (probably copy/pasted, I know)

table = resource.table
if "deleted" in table:
available_records = current.db(table.deleted != True)
else:
available_records = current.db(table._id > 0)
if available_records.select(table._id,
limitby=(0, 1)).first():
msg = DIV(S3CRUD.crud_string(resource.tablename,
"msg_no_match"),
_class="empty")
else:
msg = DIV(S3CRUD.crud_string(resource.tablename,
"msg_list_empty"),
_class="empty")
data = msg
else:
# Render the list
data = datalist.html()

return data

# END =========================================================================
42 changes: 42 additions & 0 deletions modules/templates/SAMBRO/css.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
../themes/default/layout.css
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all you need is a little extra CSS for the homepage then moving to a full theme probably isn't required (a lot more maintenance effort).
I would suggest just inserting the extra CSS into the homepage.
(via s3.stylesheets)

../themes/default/footer.css
../themes/default/widgets.css
../themes/default/shortcut.css
../themes/default/homepage.css
bootstrap/font-awesome.css
plugins/jquery.cluetip.css
plugins/jquery.dataTables.css
plugins/jquery.dataTables.responsive.css
#ui/accordion.css
ui/core.css
ui/autocomplete.css
ui/button.css
ui/datepicker.css
ui/dialog.css
# Needed for Delphi
ui/draggable.css
ui/menu.css
#ui/progressbar.css
ui/resizable.css
ui/selectmenu.css
ui/slider.css
#ui/sortable.css
#ui/spinner.css
ui/tabs.css
#ui/tooltip.css
ui/fgtimepicker.css
ui/multiselect.css
ui/timepicker-addon.css
calendars/ui-smoothness.calendars.picker.css
foundation/jquery-ui.theme.css
gis/style.css
zocial/zocial.css
../themes/default/gis.css
../themes/foundation/map.css
../themes/default/mobile.css
../themes/default/print.css
d3/nv.d3.css
../themes/default/report.css
../themes/default/survey.css
../themes/SAMBRO/style.css
# Final line required for parsing
53 changes: 53 additions & 0 deletions modules/templates/SAMBRO/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{extend "layout.html"}}{{theme=response.s3.theme}}
<link href="/eden/static/styles/../themes/SAMBRO/style.css" rel="stylesheet" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to do this via s3.stylesheets, as I explained


<div id="sambro-body" class="row">
<div class="large-12 columns">
<div class="row">

<div id="sambro-left" class="large-2 small-3 columns">
<div class="sambro-panel">
<h4><i class="icon icon-bullhorn"></i>{{=T("Alerts")}}</h4>
<div class="sambro-list">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a for item in list_of_items: etc no?

<i class="icon icon-compass"></i><a href="alert">Alert Title 1</a>
</div>
<div class="sambro-list">
<i class="icon icon-compass"></i><a href="alert">Alert Title 2</a>
</div>
<div class="sambro-list">
<i class="icon icon-compass"></i><a href="alert">Alert Title 3</a>
</div>
<div class="sambro-list">
<i class="icon icon-compass"></i><a href="alert">Alert Title 4</a>
</div>
<div class="sambro-list">
<i class="icon icon-compass"></i><a href="alert">Alert Title 5</a>
</div>
</div>
</div>

<div id="sambro-center" class="large-8 small-9 columns">
<div class="sambro-panel">
<h4>{{=T("Sahana Alert System")}}</h4>
{{=XML(map)}}
</div>
</div>

<div id="sambro-right" class="large-2 small-12 columns">
<div class="sambro-panel">
<h4>{{=T("Events")}}</h4>
<div class="sambro-list">
{{=events}}
</div>
</div>
<div class="sambro-panel">
<h4>{{=T("Feeds")}}</h4>
<div class="sambro-list">
{{=alerts}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions static/scripts/SAMBRO/sambro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$(document).ready(function () {
});
36 changes: 36 additions & 0 deletions static/themes/SAMBRO/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
body {
background-color: #FAFAFA;
}

.icon {
margin-right: 5px;
}

#sambro-body {
}

#sambro-center {
}

.sambro-list {
padding: 5px 5px;
}

.sambro-panel {
background-color: #FFF;
margin: 20px 0px 0px 0px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is responsive is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is responsive. I am using "row" and "column" in the html. The css above is for formatting only, adding some paddings and margin, doesn't have to do with layout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

margins and paddings are fine, although Foundation recommends to use rem instead of px as that would make them adapt to font scaling ;)

border: 1px solid #e7eaec;
border-top: 4px solid #e7eaec;
}

.sambro-panel div {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty? So better to remove?


.sambro-panel h4 {
border-bottom: 1px solid #DDD;
font-size: 16px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rem is recommended as it allows scaling (mobile devices often do auto-scaling of fonts)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok... thanks.

color: #888;
margin: 0px;
padding: 0px;
padding: 10px 10px;
}