summaryrefslogtreecommitdiffstats
path: root/app/helpers/my_helper.rb
blob: d105e314bd0a14f47d12f9869d38bde1e42f76d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# encoding: utf-8
#
# Redmine - project management software
# Copyright (C) 2006-2013  Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

module MyHelper
  def calendar_items(startdt, enddt)
    Issue.visible.
      where(:project_id => User.current.projects.map(&:id)).
      where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", startdt, enddt, startdt, enddt).
      includes(:project, :tracker, :priority, :assigned_to).
      all
  end

  def documents_items
    Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).all
  end

  def issuesassignedtome_items
    Issue.visible.open.
      where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
      limit(10).
      includes(:status, :project, :tracker, :priority).
      order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC").
      all
  end

  def issuesreportedbyme_items
    Issue.visible.
      where(:author_id => User.current.id).
      limit(10).
      includes(:status, :project, :tracker).
      order("#{Issue.table_name}.updated_on DESC").
      all
  end

  def issueswatched_items
    Issue.visible.on_active_project.watched_by(User.current.id).recently_updated.limit(10).all
  end

  def news_items
    News.visible.
      where(:project_id => User.current.projects.map(&:id)).
      limit(10).
      includes(:project, :author).
      order("#{News.table_name}.created_on DESC").
      all
  end

  def timelog_items
    TimeEntry.
      where("#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", User.current.id, Date.today - 6, Date.today).
      includes(:activity, :project, {:issue => [:tracker, :status]}).
      order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC").
      all
  end
end
L in a web browser. The content mode can be set in the constructor or with [methodname]#setContentMode()#, and can have the values defined in the [classname]#ContentMode# enumeration type in [package]#com.vaadin.shared.ui# package: TEXT:: The default content mode where the label contains only plain text. All characters are allowed, including the special [literal]#++<++#, [literal]#++>++#, and [literal]#++&++# characters in HTML, which are quoted properly in HTML while rendering the component. This is the default mode. PREFORMATTED:: Content mode where the label contains preformatted text. It will be, by default, rendered with a fixed-width typewriter font. Preformatted text can contain line breaks, written in Java with the [literal]#++\n++# escape sequence for a newline character (ASCII 0x0a), or tabulator characters written with [literal]#++\t++# (ASCII 0x09). HTML:: Content mode where the label contains HTML. + Please note the following security and validity warnings regarding the HTML content mode. [WARNING] .Cross-Site Scripting Warning ==== Having [classname]#Label# in HTML content mode allows pure HTML content. If the content comes from user input, you should always carefully sanitize it to prevent cross-site scripting (XSS) attacks. Please see <<../advanced/advanced-security#advanced.security.sanitizing,"Sanitizing User Input to Prevent Cross-Site Scripting">>. Also, the validity of the HTML content is not checked when rendering the component and any errors can result in an error in the browser. If the content comes from an uncertain source, you should always validate it before displaying it in the component. ==== The following example demonstrates the use of [classname]#Label# in different modes. [source, java] ---- Label textLabel = new Label( "Text where formatting characters, such as \\n, " + "and HTML, such as <b>here</b>, are quoted.", ContentMode.TEXT); Label preLabel = new Label( "Preformatted text is shown in an HTML <pre> tag.\n" + "Formatting such as\n" + " * newlines\n" + " * whitespace\n" + "and such are preserved. HTML tags, \n"+ "such as <b>bold</b>, are quoted.", ContentMode.PREFORMATTED); Label htmlLabel = new Label( "In HTML mode, all HTML formatting tags, such as \n" + "<ul>"+ " <li><b>bold</b></li>"+ " <li>itemized lists</li>"+ " <li>etc.</li>"+ "</ul> "+ "are preserved.", ContentMode.HTML); ---- The rendering will look as shown in <<figure.components.label.content-mode>>. [[figure.components.label.content-mode]] .Label Content Modes image::img/label-modes.png[width=75%, scaledwidth=100%] ifdef::web[] [[components.label.spacing]] == Spacing with a [classname]#Label# You can use a [classname]#Label# to create vertical or horizontal space in a layout. If you need a empty "line" in a vertical layout, having just a label with empty text is not enough, as it will collapse to zero height. The same goes for a label with only whitespace as the label text. You need to use a non-breaking space character, either [literal]#++&nbsp;++# or [literal]#++&#160;++#: [source, java] ---- layout.addComponent(new Label("&nbsp;", ContentMode.HTML)); ---- Using the [parameter]#ContentMode.PREFORMATTED# mode has the same effect; preformatted spaces do not collapse in a vertical layout. In a [classname]#HorizontalLayout#, the width of a space character may be unpredictable if the label font is proportional, so you can use the preformatted mode to add em-width wide spaces. If you want a gap that has adjustable width or height, you can use an empty label if you specify a height or width for it. For example, to create vertical space in a [classname]#VerticalLayout#: [source, java] ---- Label gap = new Label(); gap.setHeight("1em"); verticalLayout.addComponent(gap); ---- You can make a flexible expanding spacer by having a relatively sized empty label with [literal]#++100%++# height or width and setting the label as expanding in the layout. [source, java] ---- // A wide component bar HorizontalLayout horizontal = new HorizontalLayout(); horizontal.setWidth("100%"); // Have a component before the gap (a collapsing cell) Button button1 = new Button("I'm on the left"); horizontal.addComponent(button1); // An expanding gap spacer Label expandingGap = new Label(); expandingGap.setWidth("100%"); horizontal.addComponent(expandingGap); horizontal.setExpandRatio(expandingGap, 1.0f); // A component after the gap (a collapsing cell) Button button2 = new Button("I'm on the right"); horizontal.addComponent(button2); ---- endif::web[] [[components.label.css]] == CSS Style Rules [source, css] ---- .v-label { } pre { } /* In PREFORMATTED content mode */ ---- The [classname]#Label# component has a [literal]#++v-label++# overall style. In the [parameter]#PREFORMATTED# content mode, the text is wrapped inside a [literal]#++<pre>++# element.