Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Merge branch 'update/reference-usages' into 'develop'
Browse files Browse the repository at this point in the history
Add own string formatting for reference usages

See merge request cn-tsn/project/dbas/discuss!58
  • Loading branch information
n2o committed May 27, 2019
2 parents 575754b + d8ec798 commit 97e9774
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 60 deletions.
88 changes: 51 additions & 37 deletions src/devcards/discuss/components/references.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,60 @@

(def sample-reference-usages
[{:reference
{:uid 5,
{:uid 11,
:title
"But apparently there is an anonymous investor ensuring to pay the running costs for at least the next five years",
:host "localhost:3449",
"Einige der Hochschulen haben sich in Leitbildern oder Grundsätzen für die Forschung verpflichtet, nur zum Wohle des Menschen zu arbeiten",
:host "localhost:9500",
:path "/cards.html",
:statement-uid 68,
:author {:uid 2, :nickname "Tobias"}},
:statement-uid 94,
:author {:uid 40, :nickname "Das Känguru"}},
:arguments
[{:uid 59,
:text
"Sie argumentieren, dass E-Autos das autonome Fahren vorantreiben, weil Tesla mutig bestehende Techniken einsetzt und zeigt was sie können",
:author {:uid 1, :nickname "anonymous"},
[{:uid 81,
:texts
{:display
"Andere Teilnehmer haben gesagt, dass ein solches Leitbild sinnlos ist, weil das viel zu unkonkret ist. Jedoch haben Sie sich dann dafür interessiert, dass es eine grundsätzliche Richtung vorgibt.",
:conclusion "",
:premise "es eine grundsätzliche Richtung vorgibt",
:attacks
{:conclusion "ein solches Leitbild sinnlos ist",
:premise "das viel zu unkonkret ist"}},
:author {:uid 42, :nickname "Das Känguru"},
:issue
{:title "Elektroautos",
:slug "elektroautos",
:summary
"Elektroautos - Die Autos der Zukunft? Bitte diskutieren Sie dazu.",
:description "",
:url "/elektroautos",
{:description ".",
:date "2019-04-10 07:42:03+00:00",
:slug "public",
:is_private false,
:is_read_only false,
:title "public",
:summary ".",
:is_disabled false,
:language "de",
:date "2017-08-19 11:25:09+00:00"}}
{:uid 42,
:text
"Irgendein anderes Argument aus einer anderen Diskussion",
:author {:uid 3, :nickname "Christian"},
:url "/public",
:is_featured false}}
{:uid 76,
:texts
{:display
"Sie argumentieren, dass ein solches Leitbild sinnlos ist, weil das viel zu unkonkret ist",
:conclusion "ein solches Leitbild sinnlos ist",
:premise "das viel zu unkonkret ist",
:attacks {}},
:author {:uid 40, :nickname "Der Pinguin"},
:issue
{:title "Anderes Thema",
:slug nil,
:summary nil,
:description "",
:url "/cat-or-dog",
:language "en",
:date "2017-08-19 11:25:10+00:00"}}],
{:description ".",
:date "2019-04-10 07:42:03+00:00",
:slug "public",
:is_private false,
:is_read_only false,
:title "public",
:summary ".",
:is_disabled false,
:language "de",
:url "/public",
:is_featured false}}],
:statement
{:uid 68,
:url "/api/elektroautos/justify/68/agree",
:text "Tesla mutig bestehende Techniken einsetzt und zeigt was sie können"}}])

(def sample-reference-with-single-argument
{:argument (first (:arguments (first sample-reference-usages)))})
{:uid 94,
:url "/api/public/justify/94/agree",
:text "das viel zu unkonkret ist"}}])


;; -----------------------------------------------------------------------------
Expand All @@ -62,10 +76,10 @@
(defcard sample-passage
"<p id='discuss-text'>Currently, the city council discusses to close the University Park, because of its high running expenses of about $100.000 per year. But apparently there is an anonymous investor ensuring to pay the running costs for at least the next five years. Thanks to this anonymous person, the city does not loose a beautiful park, but this again fires up the discussion about possible savings for the future. </p>")

(defcard-om-next single-reference-usage
ref/ReferenceUsageForSingleArgumentView
(om/reconciler {:state sample-reference-with-single-argument
:parser (om/parser {:read parser/read})}))
(defcard real-discussion
"Im Jahr 2017 erteilte das Bundesministerium für Verteidigung für knapp 79 Millionen Euro Forschungsaufträge, 2016 für etwas mehr als 53 Millionen. Der größte Teil der Ausgaben fließt Instituten der F raunhofer-Gesellschaft zu. Auch das Deutsche Zentrum für Luft- und Raumfahrt steht auf der Liste ganz oben.Darüber hinaus gibt es 24 Hochschulen und Universitäten im gesamten Bundesgebiet, die 2018 für Forschung Geld vom Verteidigungsministerium erhalten haben. Das geht aus der Antwort der Bundesregierung auf die Kleine Anfrage der Linkspartei hervor, die dem ARD-Hauptstadtstudio exklusiv vorliegt."
"Einige der Hochschulen haben sich in Leitbildern oder Grundsätzen für die Forschung verpflichtet, nur zum Wohle des Menschen zu arbeiten . Das sind etwa die Universitäten in Kiel, Hannover, Duisburg-Essen und Erlangen-Nürnberg, wie eine Abfrage des ARD-Hauptstadtstudios ergab.")


(defcard-om-next reference-usages-for-all-arguments
ref/ReferenceUsagesForArgumentsView
Expand Down
3 changes: 1 addition & 2 deletions src/discuss/components/navigation.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
[discuss.translations :refer [translate]]
[discuss.utils.common :as lib]
[discuss.utils.views :as vlib]
[discuss.communication.auth :as auth]
[discuss.config :as config]))
[discuss.communication.auth :as auth]))

(defn- element
"Create one element for the navigation."
Expand Down
21 changes: 8 additions & 13 deletions src/discuss/references/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,30 @@
(defui ReferenceUsageForSingleArgumentView
"Build single usage of a reference in an argument."
static om/IQuery
(query [this] [:argument :intro])
(query [this] [:uid :author :issue :conclusion :premise])
Object
(render [this]
(let [{:keys [argument intro]} (om/props this)
{:keys [author issue]} argument]
(let [{:keys [uid author issue texts]} (om/props this)
intro (textref/reference-usage-intro (:nickname author) (:conclusion texts) (:premise texts) (:attacks texts))]
(html [:div.bs-callout.bs-callout-info
[:div.pull-right
(bs/button-default-sm
#(comlib/jump-to-argument (:slug issue) (:uid argument))
(bs/button-default-sm #(comlib/jump-to-argument (:slug issue) uid)
(vlib/fa-icon "fa-search"))]
[:a {:href "javascript:void(0)"
:onClick #(comlib/jump-to-argument (:slug issue) (:uid argument))}
:onClick #(comlib/jump-to-argument (:slug issue) uid)}
[:strong (vlib/safe-html intro)]]
[:div (t :common :author) ": " (:nickname author)]
[:div (t :common :issue) ": " (:title issue)]]))))
(def reference-usage-for-single-argument (om/factory ReferenceUsageForSingleArgumentView {:keyfn :argument}))
(def reference-usage-for-single-argument (om/factory ReferenceUsageForSingleArgumentView {:keyfn :uid}))

(defui ReferenceUsagesForArgumentsView
static om/IQuery
(query [this] [:arguments])
Object
(render [this]
(let [{:keys [arguments raw]} (om/props this)]
(let [{:keys [arguments]} (om/props this)]
(html [:div
(map
#(reference-usage-for-single-argument
{:argument %
:intro (textref/reference-usage-intro (get-in % [:author :nickname]) (:conclusions raw) (:premises raw))})
arguments)]))))
(map reference-usage-for-single-argument arguments)]))))
(def reference-usages-for-arguments (om/factory ReferenceUsagesForArgumentsView {:keyfn :arguments}))

(defui UsagesView
Expand Down
16 changes: 16 additions & 0 deletions src/discuss/texts/lib.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns discuss.texts.lib
(:require [cljs.spec.alpha :as s]
[clojure.string :as string]
[goog.string :refer [format]]
[goog.string.format]
[discuss.translations :refer [translate] :rename {translate t}]))

(defn join-with-and
Expand All @@ -11,3 +13,17 @@
:args (s/cat :col (s/coll-of string?))
:ret string?)


;; -----------------------------------------------------------------------------
;; Highlight strings with html classes

(defn highlight-premise [premise]
(format "<span class=\"text-info\">%s</span>" premise))

(defn highlight-conclusion [premise]
(format "<span class=\"text-warning\">%s</span>" premise))

(defn highlight-undercut [premise]
(format "<span class=\"text-primary\">%s</span>" premise))


27 changes: 19 additions & 8 deletions src/discuss/texts/references.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@
(:require [cljs.spec.alpha :as s]
[goog.string :refer [format]]
[goog.string.format]
[discuss.texts.lib :as textlib]
[discuss.translations :refer [translate] :rename {translate t}]))
[discuss.translations :refer [translate] :rename {translate t}]
[discuss.texts.lib :as textlib]))

(defn reference-usage-intro
"Construct reference usage intro."
[nickname conclusions premises]
(let [joined-conclusions (textlib/join-with-and conclusions)
joined-premises (textlib/join-with-and premises)]
(format "%s %s %s, %s %s" nickname (t :common :argue/that) joined-conclusions (t :common :because) joined-premises)))
"Construct reference usage intro. If attacks are provided, the target attack is
an argument itself, which makes the whole attack an undercut."
[nickname conclusion premise attacks]
(if (seq attacks)
(format "%s glaubt nicht, dass \"%s\" zu \"%s\" passt, weil %s."
nickname
(textlib/highlight-premise (:premise attacks))
(textlib/highlight-conclusion (:conclusion attacks))
(textlib/highlight-undercut premise))
(format "%s %s %s, %s %s."
nickname
(t :common :argue/that)
(textlib/highlight-conclusion conclusion)
(t :common :because)
(textlib/highlight-premise premise))))

(s/fdef reference-usage-intro
:args (s/cat :nickname string? :conclusions (s/coll-of string?) :premises (s/coll-of string?))
:args (s/cat :nickname string? :conclusion string? :premise string? :attacks (s/or :empty nil? :undercut map?))
:ret string?)

0 comments on commit 97e9774

Please sign in to comment.