Skip to content

Commit ccba785

Browse files
author
kaptron
committed
[WIP] Initial setup of CollectionCard::Section
- for now, sections are just created with one click and hardcoded at 3x3
1 parent ca91a56 commit ccba785

17 files changed

+122
-5
lines changed

app/controllers/api/v1/collection_cards_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ def collection_card_attributes
783783
show_replace
784784
card_type
785785
section_type
786+
section_name
786787
font_color
787788
font_background
788789
]

app/javascript/ui/grid/FoamcoreGrid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ class FoamcoreGrid extends React.Component {
490490
const { collection, trackCollectionUpdated, uiStore } = this.props
491491
let { height, width } = uiStore.placeholderSpot
492492
// Some double-checking validations
493+
// TODO: allow sections to be as big as you want?
493494
const maxHeight = this.calcEdgeRow(card)
494495
const maxWidth = this.calcEdgeCol(card)
495496
if (height > maxHeight) height = maxHeight

app/javascript/ui/grid/HotCell.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,19 @@ class HotCell extends React.Component {
175175
}
176176

177177
get collectionTypes() {
178-
return [
178+
const { isFourWideBoard } = this.props
179+
let types = [
179180
{ name: 'collection', description: 'Create Collection' },
180181
{ name: 'foamcoreBoard', description: 'Create Foamcore Board' },
181182
{ name: 'searchCollection', description: 'Create Search Collection' },
182183
{ name: 'submissionBox', description: 'Create Submission Box' },
184+
{ name: 'section', description: 'Create Section' },
183185
{ name: 'testCollection', description: 'Get Feedback' },
184186
]
187+
if (isFourWideBoard) {
188+
types = _.reject(types, t => t.name === 'section')
189+
}
190+
return types
185191
}
186192

187193
get textTypes() {

app/javascript/ui/grid/HotCellQuadrant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ const nameToIcon = {
9292
template: TemplateIcon,
9393
useTemplate: TemplateIcon,
9494
testCollection: FeedbackIcon,
95+
// TODO: section icon
96+
section: TemplateIcon,
9597
text: TextIcon,
9698
video: VideoIcon,
9799
}

app/javascript/ui/grid/MovableGridCard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class MovableGridCard extends React.Component {
288288
width: card.width + Math.floor(delta.width / gridW + pad),
289289
height: card.height + Math.floor(delta.height / gridH + pad),
290290
}
291+
// TODO: allow sections to be as big as you want?
291292
// e.g. if card.width is 4, but we're at 2 columns, max out at cardWidth = 2
292293
newSize.width = Math.max(Math.min(newSize.width, cols), 1)
293294
// always max out height at 2

app/javascript/ui/grid/interactionLayer/FoamcoreInteractionLayer.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import RowActions from './RowActions'
1414
import PositionedBlankCard from '~/ui/grid/interactionLayer/PositionedBlankCard'
1515
import FoamcoreHotEdge from '~/ui/grid/FoamcoreHotEdge'
1616
import FilestackUpload, { MAX_SIZE } from '~/utils/FilestackUpload'
17-
import v, { FOAMCORE_INTERACTION_LAYER, ITEM_TYPES } from '~/utils/variables'
17+
import v, {
18+
FOAMCORE_INTERACTION_LAYER,
19+
ITEM_TYPES,
20+
} from '~/utils/variables'
1821
import googleTagManager from '~/vendor/googleTagManager'
1922

2023
const DragLayerWrapper = styled.div`
@@ -301,6 +304,23 @@ class FoamcoreInteractionLayer extends React.Component {
301304
})
302305
}
303306

307+
createSection = async ({ col, row, height = 3, width = 3 } = {}) => {
308+
const { collection, apiStore } = this.props
309+
const attrs = {
310+
col,
311+
row,
312+
width,
313+
height,
314+
section_name: 'New Section',
315+
card_type: 'section',
316+
parent_id: collection.id,
317+
}
318+
319+
const card = new CollectionCard(attrs, apiStore)
320+
console.log('creating new section at', row, col)
321+
card.API_create()
322+
}
323+
304324
@action
305325
resetHoveringRowCol() {
306326
this.hoveringRowCol = { row: null, col: null }
@@ -415,6 +435,12 @@ class FoamcoreInteractionLayer extends React.Component {
415435
col,
416436
})
417437
return
438+
} else if (contentType === 'section') {
439+
this.createSection({
440+
row,
441+
col,
442+
})
443+
return
418444
}
419445

420446
// If we're already in the process of creating a hot edge and placeholder

app/javascript/utils/variables.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const COLLECTION_CARD_TYPES = {
4949
PRIMARY: 'CollectionCard::Primary',
5050
LINK: 'CollectionCard::Link',
5151
PLACEHOLDER: 'CollectionCard::Placeholder',
52+
SECTION: 'CollectionCard::Section',
5253
}
5354

5455
export const DATASET_CHART_TYPES = {

app/models/collection.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ class Collection < ApplicationRecord
168168
foreign_key: :parent_id,
169169
inverse_of: :parent
170170

171+
# sections within this collection
172+
has_many :section_collection_cards,
173+
-> { active.ordered },
174+
class_name: 'CollectionCard::Section',
175+
foreign_key: :parent_id,
176+
inverse_of: :parent
177+
171178
has_many :hidden_collection_cards,
172179
-> { active.hidden },
173180
class_name: 'CollectionCard::Primary',

app/models/collection_card.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# parent_snapshot :jsonb
2222
# pinned :boolean default(FALSE)
2323
# row :integer
24+
# section_name :string
2425
# section_type :integer
2526
# show_replace :boolean default(TRUE)
2627
# type :string
@@ -83,6 +84,7 @@ class CollectionCard < ApplicationRecord
8384
validates :parent, presence: true
8485
validate :single_item_or_collection_is_present
8586
validate :parent_is_not_readonly, on: :create
87+
# section_type is used by TestCollections e.g. for the "ideas section"
8688
validates :section_type, presence: true, if: :parent_test_collection?
8789

8890
delegate :board_collection?, :test_collection?,
@@ -331,6 +333,10 @@ def placeholder?
331333
is_a? CollectionCard::Placeholder
332334
end
333335

336+
def section?
337+
is_a? CollectionCard::Section
338+
end
339+
334340
def master_template_card?
335341
# does this card live in a MasterTemplate?
336342
parent&.master_template?

app/models/collection_card/link.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# parent_snapshot :jsonb
2222
# pinned :boolean default(FALSE)
2323
# row :integer
24+
# section_name :string
2425
# section_type :integer
2526
# show_replace :boolean default(TRUE)
2627
# type :string

0 commit comments

Comments
 (0)