Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
27808a5e
Unverified
Commit
27808a5e
authored
5 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup for DashboardCard util fns
parent
55ba22d7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/dashboard_card.clj
+33
-32
33 additions, 32 deletions
src/metabase/models/dashboard_card.clj
src/metabase/util.clj
+1
-1
1 addition, 1 deletion
src/metabase/util.clj
with
34 additions
and
33 deletions
src/metabase/models/dashboard_card.clj
+
33
−
32
View file @
27808a5e
...
...
@@ -20,8 +20,8 @@
(
declare
series
)
(
defn-
perms-objects-set
"Return the set of permissions required to
READ-OR-WRITE
this
`
DashboardCard
`
.
If `:card` and `:series` are already
hydrated this method doesn't need to make any DB calls."
"Return the set of permissions required to
`read-or-write`
this DashboardCard.
If `:card` and `:series` are already
hydrated this method doesn't need to make any DB calls."
[
dashcard
read-or-write
]
(
let
[
card
(
or
(
:card
dashcard
)
(
db/select-one
[
Card
:dataset_query
]
:id
(
u/get-id
(
:card_id
dashcard
))))
...
...
@@ -58,14 +58,14 @@
;;; --------------------------------------------------- HYDRATION ----------------------------------------------------
(
defn
dashboard
"Return the
`
Dashboard
`
associated with the
`
DashboardCard
`
."
"Return the Dashboard associated with the DashboardCard."
[{
:keys
[
dashboard_id
]}]
{
:pre
[(
integer?
dashboard_id
)]}
(
db/select-one
'Dashboard,
:id
dashboard_id
))
(
defn
^
:hydrate
series
"Return the `Cards` associated as additional series on this
`
DashboardCard
`
."
"Return the `Cards` associated as additional series on this DashboardCard."
[{
:keys
[
id
]}]
(
db/select
[
Card
:id
:name
:description
:display
:dataset_query
:visualization_settings
:collection_id
]
(
mdb/join
[
Card
:id
]
[
DashboardCardSeries
:card_id
])
...
...
@@ -75,25 +75,22 @@
;;; ---------------------------------------------------- CRUD FNS ----------------------------------------------------
(
defn
retrieve-dashboard-card
"Fetch a single `DashboardCard` by its ID value."
[
id
]
{
:pre
[(
integer?
id
)]}
(
s/defn
retrieve-dashboard-card
"Fetch a single DashboardCard by its ID value."
[
id
:-
su/IntGreaterThanZero
]
(
->
(
DashboardCard
id
)
(
hydrate
:series
)))
(
defn
update-dashboard-card-series!
"Update the
`
DashboardCardSeries
`
for a given
`
DashboardCard
`
.
CARD-IDS
should be a definitive collection of *all* IDs of cards for the dashboard card in the desired order.
(
s/
defn
update-dashboard-card-series!
"Update the DashboardCardSeries for a given DashboardCard.
`card-ids`
should be a definitive collection of *all* IDs of cards for the dashboard card in the desired order.
* If an ID in
CARD-IDS
has no corresponding existing
`
DashboardCardSeries
`
object, one will be created.
* If an existing
`
DashboardCardSeries
`
has no corresponding ID in
CARD-IDs
, it will be deleted.
* All cards will be updated with a `position` according to their place in the collection of
CARD-IDS
"
* If an ID in
`card-ids`
has no corresponding existing DashboardCardSeries object, one will be created.
* If an existing DashboardCardSeries has no corresponding ID in
`card-ids`
, it will be deleted.
* All cards will be updated with a `position` according to their place in the collection of
`card-ids`
"
{
:arglists
'
([
dashboard-card
card-ids
])}
[{
:keys
[
id
]}
card-ids
]
{
:pre
[(
integer?
id
)
(
sequential?
card-ids
)
(
every?
integer?
card-ids
)]}
[{
:keys
[
id
]}
:-
{
:id
su/IntGreaterThanZero,
s/Keyword
s/Any
}
card-ids
:-
[
su/IntGreaterThanZero
]]
;; first off, just delete all series on the dashboard card (we add them again below)
(
db/delete!
DashboardCardSeries
:dashboardcard_id
id
)
;; now just insert all of the series that were given to us
...
...
@@ -103,14 +100,18 @@
card-ids
)]
(
db/insert-many!
DashboardCardSeries
cards
))))
(
defn
update-dashboard-card!
"Update an existing `DashboardCard`, including all `DashboardCardSeries`.
Returns the updated `DashboardCard` or throws an Exception."
[{
:keys
[
id
series
parameter_mappings
visualization_settings
]
:as
dashboard-card
}]
{
:pre
[(
integer?
id
)
(
u/maybe?
u/sequence-of-maps?
parameter_mappings
)
(
u/maybe?
map?
visualization_settings
)
(
every?
integer?
series
)]}
(
def
^
:private
DashboardCardUpdates
{
:id
su/IntGreaterThanZero
(
s/optional-key
:parameter_mappings
)
(
s/maybe
[
su/Map
])
(
s/optional-key
:visualization_settings
)
(
s/maybe
su/Map
)
;; series is a sequence of IDs of additional cards after the first to include as "additional serieses"
(
s/optional-key
:series
)
(
s/maybe
[
su/IntGreaterThanZero
])
s/Keyword
s/Any
})
(
s/defn
update-dashboard-card!
"Update an existing DashboardCard` including all DashboardCardSeries.
Returns the updated DashboardCard or throws an Exception."
[{
:keys
[
id
series
parameter_mappings
visualization_settings
]
:as
dashboard-card
}
:-
DashboardCardUpdates
]
(
let
[{
:keys
[
sizeX
sizeY
row
col
series
]}
(
merge
{
:series
[]}
dashboard-card
)]
(
db/transaction
;; update the dashcard itself (positional attributes)
...
...
@@ -123,9 +124,9 @@
:parameter_mappings
parameter_mappings
:visualization_settings
visualization_settings
))
;; update series (only if they changed)
(
when
(
not=
series
(
map
:card_id
(
db/select
[
DashboardCardSeries
:card_id
]
:dashboardcard_id
id
{
:order-by
[[
:position
:asc
]]})))
(
when
-
not
(
=
series
(
map
:card_id
(
db/select
[
DashboardCardSeries
:card_id
]
:dashboardcard_id
id
{
:order-by
[[
:position
:asc
]]})))
(
update-dashboard-card-series!
dashboard-card
series
))
;; fetch the fully updated dashboard card then return it (and fire off an event)
(
->>
(
retrieve-dashboard-card
id
)
...
...
@@ -140,8 +141,8 @@
s/Keyword
s/Any
})
(
s/defn
create-dashboard-card!
"Create a new
`
DashboardCard
`
by inserting it into the database along with all associated pieces of data such as
`
DashboardCardSeries
`
. Returns the newly created
`
DashboardCard
`
or throws an Exception."
"Create a new DashboardCard by inserting it into the database along with all associated pieces of data such as
DashboardCardSeries. Returns the newly created DashboardCard or throws an Exception."
[
dashboard-card
:-
NewDashboardCard
]
(
let
[{
:keys
[
dashboard_id
card_id
creator_id
parameter_mappings
visualization_settings
sizeX
sizeY
row
col
series
]
:or
{
sizeX
2
,
sizeY
2
,
series
[]}}
dashboard-card
]
...
...
@@ -164,7 +165,7 @@
(
dissoc
dashcard
:actor_id
))))))
(
defn
delete-dashboard-card!
"Delete a
`
DashboardCard`
.
"
"Delete a DashboardCard`"
[
dashboard-card
user-id
]
{
:pre
[(
map?
dashboard-card
)
(
integer?
user-id
)]}
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util.clj
+
1
−
1
View file @
27808a5e
...
...
@@ -15,7 +15,7 @@
[
metabase.util.i18n
:refer
[
trs
tru
]]
[
ring.util.codec
:as
codec
])
(
:import
[
java.io
BufferedReader
Reader
]
[
java.net
InetAddress
InetSocketAddress
Socket
URL
]
[
java.net
InetAddress
InetSocketAddress
Socket
]
[
java.text
Normalizer
Normalizer$Form
]
java.util.concurrent.TimeoutException
java.util.Locale
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment