forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While a community will eventually have multiple organizers, we need at least one person to be responsible if an issue is raised. The community has one owner. In later PRs, there will be multiple members and multiple organizers.
- Loading branch information
Showing
36 changed files
with
1,184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*global showMap,formMapInput*/ | ||
|
||
|
||
$(document).ready(function () { | ||
if ($("#community_map_form").length) { | ||
formMapInput("community_map_form", "community"); | ||
} else if ($("#community_map").length) { | ||
showMap("community_map"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Place all the styles related to the Communities controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ | ||
|
||
.community_details { | ||
h1 { | ||
margin-top: 0; | ||
} | ||
label { | ||
font-weight: bold; | ||
} | ||
ul { | ||
display: inline-block; | ||
} | ||
ul > li { | ||
display: inline-block; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
class CommunitiesController < ApplicationController | ||
include UserMethods | ||
|
||
layout "site" | ||
before_action :authorize_web | ||
|
||
before_action :set_community, :only => [:edit, :show, :update] | ||
|
||
helper_method :recent_changesets | ||
|
||
load_and_authorize_resource :except => [:create, :new] | ||
authorize_resource | ||
|
||
def index | ||
display_name = params[:user_display_name] | ||
if display_name | ||
@user = User.active.find_by(:display_name => display_name) | ||
if @user | ||
@title = t ".title", :display_name => @user.display_name | ||
@communities_organized = @user.communities_organized | ||
else | ||
render_unknown_user display_name | ||
return | ||
end | ||
elsif current_user | ||
@title = t ".title", :display_name => current_user.display_name | ||
@communities_organized = current_user.communities_organized | ||
end | ||
|
||
@all_communities = Community.order(:name) | ||
end | ||
|
||
# GET /communities/mycity | ||
# GET /communities/mycity.json | ||
def show; end | ||
|
||
def new | ||
@title = t ".title" | ||
@community = Community.new | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@community = Community.new(community_params) | ||
@community.organizer = current_user | ||
if @community.save | ||
redirect_to @community, :notice => t(".success") | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def update | ||
if @community.update(community_params) | ||
redirect_to @community, :notice => t(".success") | ||
else | ||
flash.now[:alert] = t(".failure") | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def recent_changesets | ||
bbox = @community.bbox.to_scaled | ||
Changeset | ||
.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?", | ||
bbox.max_lon.to_i, bbox.min_lon.to_i, bbox.max_lat.to_i, bbox.min_lat.to_i) | ||
.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments) | ||
end | ||
|
||
def set_community | ||
@community = Community.friendly.find(params[:id]) | ||
end | ||
|
||
def community_params | ||
params.require(:community).permit( | ||
:name, :location, :latitude, :longitude, | ||
:min_lat, :max_lat, :min_lon, :max_lon, | ||
:description | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# == Schema Information | ||
# | ||
# Table name: communities | ||
# | ||
# id :bigint(8) not null, primary key | ||
# name :string not null | ||
# description :text not null | ||
# organizer_id :bigint(8) not null | ||
# slug :string not null | ||
# location :string not null | ||
# latitude :float not null | ||
# longitude :float not null | ||
# min_lat :float not null | ||
# max_lat :float not null | ||
# min_lon :float not null | ||
# max_lon :float not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_communities_on_organizer_id (organizer_id) | ||
# index_communities_on_slug (slug) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (organizer_id => users.id) | ||
# | ||
|
||
# At this time a community has one organizer. The first organizer is | ||
# the user that created the community. | ||
|
||
class Community < ApplicationRecord | ||
extend FriendlyId | ||
friendly_id :name, :use => :slugged | ||
|
||
belongs_to :organizer, :class_name => "User" | ||
|
||
validates :name, :presence => true, :length => 1..255, :characters => true | ||
validates :description, :presence => true, :length => 1..1023, :characters => true | ||
validates :location, :presence => true, :length => 1..255, :characters => true | ||
validates :latitude, :numericality => true, :inclusion => { :in => -90..90 } | ||
validates :longitude, :numericality => true, :inclusion => { :in => -180..180 } | ||
validates :min_lat, :numericality => true, :inclusion => { :in => -90.0..90.0 } | ||
validates :max_lat, :numericality => true, :inclusion => { :in => -90.0..90.0 } | ||
validates :min_lon, :numericality => true, :inclusion => { :in => -180.0..180.0 } | ||
validates :max_lon, :numericality => true, :inclusion => { :in => -180.0..180.0 } | ||
|
||
def longitude=(longitude) | ||
super(OSM.normalize_longitude(longitude)) | ||
end | ||
|
||
def min_lon=(longitude) | ||
super(OSM.normalize_longitude(longitude)) | ||
end | ||
|
||
def max_lon=(longitude) | ||
super(OSM.normalize_longitude(longitude)) | ||
end | ||
|
||
def bbox | ||
BoundingBox.new(min_lon, min_lat, max_lon, max_lat) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= stylesheet_link_tag "communities" %> | ||
<%= javascript_include_tag "communities" %> | ||
|
||
<p> | ||
All fields are required. | ||
</p> | ||
<%= bootstrap_form_for @community do |form| %> | ||
<%= form.text_field :name, :id => :community_name %> | ||
<%= form.text_field :location, :id => :community_location %> | ||
<div class="row"> | ||
<%= form.text_field :latitude, :wrapper_class => "col-sm-6", :id => :community_latitude %> | ||
<%= form.text_field :longitude, :wrapper_class => "col-sm-6", :id => :community_longitude %> | ||
</div> | ||
<div class="community_set_location"> | ||
<div id="community_map_form" class="content_map"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-4"></div> | ||
<%= form.text_field :max_lat, :wrapper_class => "col-sm-4", :id => :community_max_lat %> | ||
</div> | ||
<div class="row"> | ||
<%= form.text_field :min_lon, :wrapper_class => "col-sm-4", :id => :community_min_lon %> | ||
<div class="col-sm-4"></div> | ||
<%= form.text_field :max_lon, :wrapper_class => "col-sm-4", :id => :community_max_lon %> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-4"></div> | ||
<%= form.text_field :min_lat, :wrapper_class => "col-sm-4", :id => :community_min_lat %> | ||
</div> | ||
<%= form.text_area :description, :id => :community_description %> | ||
<%= form.primary %> | ||
<% end %> |
Oops, something went wrong.