Class: Dhatu::Project

Inherits:
ApplicationRecord show all
Includes:
Featureable, Publishable
Defined in:
app/models/dhatu/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.image_configurationObject

Image Configuration




75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/dhatu/project.rb', line 75

def self.image_configuration
  {
    "Image::CoverImage" => {
      max_upload_limit: 10485760,
      min_upload_limit: 1,
      resolutions: [800, 400],
      form_upload_image_label: "Upload a new Image",
      form_title: "Upload an Image",
      form_sub_title: "Please read the instructions below:",
      form_instructions: [
        "the filename should be in .jpg / .jpeg or .png format",
        "the image resolutions should be <strong>800 x 400 Pixels</strong>",
        "the file size should be greater than 100 Kb and or lesser than <strong>10 MB</strong>",
        "Note: most cameras and camera phones will produce images bigger than this"
      ]
    },
    "Image::GalleryImage" => {
      max_upload_limit: 10485760,
      min_upload_limit: 1,
      resolutions: [800, 400],
      form_upload_image_label: "Upload a new Image",
      form_title: "Upload an Image",
      form_sub_title: "Please read the instructions below:",
      form_instructions: [
        "the filename should be in .jpg / .jpeg or .png format",
        "the image resolutions should be <strong>800 x 400 Pixels</strong>",
        "the file size should be greater than 100 Kb and or lesser than <strong>10 MB</strong>",
        "Note: most cameras and camera phones will produce images bigger than this"
      ]
    }  
  }
  
end

.save_row_data(hsh) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/dhatu/project.rb', line 39

def self.save_row_data(hsh)
  # Initializing error hash for displaying all errors altogether
  error_object = Kuppayam::Importer::ErrorHash.new

  return error_object if hsh[:name].to_s.strip.blank?

  project = Dhatu::Project.find_by_name(hsh[:name].to_s.strip) || Dhatu::Project.new
  project.name = hsh[:name].to_s.strip
  project.short_description = hsh[:short_description].to_s.strip
  project.description = hsh[:description].to_s.strip
  project.client = hsh[:client].to_s.strip
  project.category = Dhatu::Category.find_by_name(hsh[:category].to_s.strip)
  project.status = hsh[:status].to_s.strip.blank? ? PUBLISHED : hsh[:status].to_s.strip
  project.featured = hsh[:featured].to_s.strip || true
  project.priority = hsh[:priority].to_s.strip || 1

  project.generate_permalink

  if project.valid?
    begin
      project.save!
    rescue Exception => e
      summary = "uncaught #{e} exception while handling connection: #{e.message}"
      details = "Stack trace: #{e.backtrace.map {|l| "  #{l}\n"}.join}"
      error_object.errors << { summary: summary, details: details }        
    end
  else
    summary = "Error while saving project: #{project.name}"
    details = "Error! #{project.errors.full_messages.to_sentence}"
    error_object.errors << { summary: summary, details: details }
  end
  return error_object
end

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'app/models/dhatu/project.rb', line 134

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


130
131
132
# File 'app/models/dhatu/project.rb', line 130

def can_be_edited?
  status?(:published) or status?(:unpublished)
end

#display_nameObject



123
124
125
# File 'app/models/dhatu/project.rb', line 123

def display_name
  "#{name_was}"
end


119
120
121
# File 'app/models/dhatu/project.rb', line 119

def generate_permalink
  self.permalink = self.name.parameterize[0..32]
end

#to_paramObject

Generic Methods




115
116
117
# File 'app/models/dhatu/project.rb', line 115

def to_param
  "#{id}-#{name.parameterize[0..32]}"
end