Skip to content

Commit

Permalink
add more recent PR content
Browse files Browse the repository at this point in the history
  • Loading branch information
rudokemper committed Apr 29, 2022
1 parent 3b74e8c commit d4ac4a3
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
4 changes: 4 additions & 0 deletions rails/app/assets/stylesheets/components/_balloon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
margin: 10px 0;
}

&-audio {
width: 100%;
}

.mapboxgl-popup-content {
h1, h2, h3, h4, h5, p, img {
margin: 0;
Expand Down
9 changes: 9 additions & 0 deletions rails/app/controllers/admin/places_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@ def import_page
def export_sample_csv
send_data Place.export_sample_csv, filename: "sample_places.csv"
end

def destroy_name_audio
return unless current_user.admin?

place = Place.find(params[:record_id])
place.name_audio.purge

redirect_back(fallback_location: "/")
end
end
end
6 changes: 4 additions & 2 deletions rails/app/dashboards/place_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class PlaceDashboard < Administrate::BaseDashboard
long: Field::String.with_options(searchable: false),
lat: Field::String.with_options(searchable: false),
region: RegionField,
photo: Field::ActiveStorage.with_options({destroy_path: :admin_places_path}),
type_of_place: TypeOfPlaceField,
photo: Field::ActiveStorage.with_options(destroy_path: :admin_places_path),
name_audio: Field::ActiveStorage.with_options(destroy_path: :admin_places_destroy_name_audio_path), type_of_place: TypeOfPlaceField,
community: Field::BelongsTo,
created_at: Field::DateTime,
updated_at: Field::DateTime,
Expand Down Expand Up @@ -46,6 +46,7 @@ class PlaceDashboard < Administrate::BaseDashboard
:lat,
:stories,
:photo,
:name_audio,
:created_at,
:updated_at,
].freeze
Expand All @@ -56,6 +57,7 @@ class PlaceDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = [
:name,
:photo,
:name_audio,
:description,
:type_of_place,
:region,
Expand Down
71 changes: 68 additions & 3 deletions rails/app/javascript/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class App extends Component {
bearing: PropTypes.string
};



componentDidMount() {
const points = this.getPointsFromStories(this.state.stories);
this.setState({ points: points });
Expand Down Expand Up @@ -111,7 +113,7 @@ class App extends Component {
break;
}
case I18n.t("topic"): {
// second category: Topic
// fourth category: Topic
const topicSet = new Set(
this.props.stories
.map(story => story.topic)
Expand All @@ -120,6 +122,28 @@ class App extends Component {
filterMap[category] = Array.from(topicSet).filter(item => item).sort();
break;
}
case I18n.t("language"): {
// fifth category: Language
const languageSet = new Set(
this.props.stories
.map(story => story.language)
.flat()
);
filterMap[category] = Array.from(languageSet).filter(item => item).sort();
break;
}
case I18n.t("helpers.label.speaker.speaker_community"): {
// sixth category: Community
const communitySet = new Set(
this.props.stories
.map(story => {
return story.speakers.map(speaker => speaker.speaker_community);
})
.flat()
);
filterMap[category] = Array.from(communitySet).filter(item => item).sort();
break;
}
}
});
return filterMap;
Expand Down Expand Up @@ -189,6 +213,32 @@ class App extends Component {
});
break;
}
case I18n.t("language"): {
// fifth category: language
filteredStories = this.props.stories.filter(story => {
if (story.language) {
return (
story.language &&
story.language.toLowerCase() === item.toLowerCase()
)
}
});
break;
}
case I18n.t("helpers.label.speaker.speaker_community"): {
// sixth category: community
filteredStories = this.props.stories
.filter((story) => story.speakers
.some(speaker => speaker.speaker_community && speaker.speaker_community.toLowerCase() === item.toLowerCase())
)
.map(story => {
let n = Object.assign({}, story)
n.speakers = n.speakers
.filter(speaker => speaker.speaker_community && speaker.speaker_community.toLowerCase() === item.toLowerCase())
return n
});
break;
}
}
if (filteredStories) {
const filteredPoints = this.getPointsFromStories(filteredStories);
Expand Down Expand Up @@ -276,6 +326,21 @@ class App extends Component {
this.setState({ activePoint: point, framedView });
};


// build category list based that excludes empty category sets
buildFilterCategories = () => {
const variableCategories = [I18n.t("topic"), I18n.t("language"), I18n.t("helpers.label.speaker.speaker_community"),]
let categories = this.filterMap();

Object.keys(categories).map(cat => {
if (categories[cat].length === 0 && variableCategories.includes(cat)) {
delete categories[cat]
}
})
let filteredCategories = Object.keys(categories)
return filteredCategories
}

render() {
return (
<div>
Expand Down Expand Up @@ -304,7 +369,7 @@ class App extends Component {
activeStory={this.state.activeStory}
stories={this.state.stories}
handleStoriesChanged={this.handleStoriesChanged}
categories={FILTER_CATEGORIES}
categories={this.buildFilterCategories()}
filterMap={this.filterMap()}
handleFilter={this.handleFilter}
clearFilteredStories={this.resetStoriesAndMap}
Expand All @@ -322,4 +387,4 @@ class App extends Component {
);
}
}
export default App;
export default App;
2 changes: 1 addition & 1 deletion rails/app/javascript/constants/FilterConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* global I18n */

export default [I18n.t("region"), I18n.t("place_type"), I18n.t("speaker"), I18n.t("topic")].sort();
export default [I18n.t("region"), I18n.t("place_type"), I18n.t("speaker"), I18n.t("topic"), I18n.t("language"), I18n.t("helpers.label.speaker.speaker_community")].sort();
9 changes: 9 additions & 0 deletions rails/app/models/place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class Place < ApplicationRecord
belongs_to :community
has_and_belongs_to_many :stories
has_one_attached :photo
has_one_attached :name_audio
validate :photo_format
validates :name_audio, blob: { content_type: ['audio/mpeg', 'audio/wav'] }
validates :lat, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }, allow_blank: true
validates :long, numericality: { greater_than_or_equal_to: -180, less_than_or_equal_to: 180 }, allow_blank: true
has_many :interview_stories, class_name: "Story", foreign_key: "interview_location_id"
Expand All @@ -29,6 +31,12 @@ def photo_url
end
end

def name_audio_url
if name_audio.attached?
Rails.application.routes.url_helpers.rails_blob_path(name_audio, only_path: true)
end
end

def point_geojson
RGeo::GeoJSON.encode geojson
end
Expand All @@ -53,6 +61,7 @@ def geojson
region: region,
type_of_place: type_of_place,
photo_url: photo_url,
name_audio_url: name_audio_url,
stories: stories
)
end
Expand Down
1 change: 1 addition & 0 deletions rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
get :export_sample_csv
end
end
delete :places_destroy_name_audio, to: 'places#destroy_name_audio'
resources :curriculum_stories
resources :themes
# resources :media_links
Expand Down

0 comments on commit d4ac4a3

Please sign in to comment.