Skip to content

Commit

Permalink
Merge pull request #626 from statonlab/624-recent-updates-feed-on-mai…
Browse files Browse the repository at this point in the history
…n-page

624 recent updates feed on main page
  • Loading branch information
florence-77 authored Aug 9, 2024
2 parents 4836c12 + 4f2a84d commit ec22cbe
Show file tree
Hide file tree
Showing 24 changed files with 892 additions and 37 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Traits\Responds;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, Responds;
}
93 changes: 93 additions & 0 deletions app/Http/Controllers/TreetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Treet;

class TreetController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$this->validate($request, [
'limit' => 'nullable|integer|min:6|max:90',
]);

$limit = $request->limit ?: 10;

$treets = Treet::select(['id','app_name', 'image_path', 'description', 'url', 'created_at'])
->orderBy('created_at', 'desc')
->limit($limit)
->get();

$treets->map(function ($treet) {
$treet->date = $treet->created_at->format('m/d/y');
});

return $this->success($treets);
}

/**
* Show the form for creating a new resource.
*/
public function create(Request $request)
{
$this->authorize('create', Treet::class);

$urls = ['Treesnap' => "https://treesnap.org/",
'FlorestaDB' => "https://app.florestadb.org/login",
'HealthyWoods' => "https://healthywoodsapp.org/",
'Avid Deer' => "https://aviddeer.com/",
'Eastern Forest Pests' => "https://easternforestpests.com/"];


$treet = Treet::create([
'app_name' => $request->app_name,
'image_path' => $request->image_path,
'description' => $request->description,
'url' => $urls[$request->app_name]
]);

return $this->created($treet);

}
/**
* Show the form for editing the specified resource.
*/
public function edit(Request $request, Treet $treet)
{
$urls = ['Treesnap' => "https://treesnap.org/",
'FlorestaDB' => "https://app.florestadb.org/login",
'HealthyWoods' => "https://healthywoodsapp.org/",
'Avid Deer' => "https://aviddeer.com/",
'Eastern Forest Pests' => "https://easternforestpests.com/"];

$this->authorize('edit', Treet::class);

$treet = Treet::find($request->id);

$treet->update([
'app_name' => $request->app_name ?: $treet->app_name,
'image_path' => $request->image_path ?: $treet->image_path,
'description' => $request->description ?: $treet->description,
'url' => $urls[$request->app_name]
]);
return $this->success($treet);

}

/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request, Treet $treet)
{
$this->authorize('destroy', Treet::class);

$treet->find($request->id)->delete();
return $this->success($treet);
}

}
69 changes: 69 additions & 0 deletions app/Policies/TreetPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Policies;

use App\Treet;
use App\User;
use Illuminate\Auth\Access\Response;

class TreetPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
//
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Treet $treet): bool
{
//
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->isAdmin();

}

/**
* Determine whether the user can update the model.
*/
public function edit(User $user): bool
{
return $user->isAdmin();

}

/**
* Determine whether the user can delete the model.
*/
public function destroy(User $user): bool
{
return $user->isAdmin();

}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Treet $treet): bool
{
//
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Treet $treet): bool
{
//
}
}
22 changes: 22 additions & 0 deletions app/Treet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Treet extends Model
{
use HasFactory;

protected $fillable = [
'app_name',
'image_path',
'description',
'url'
];

protected $casts = [
'created_at' => 'datetime',
];
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
Expand Down
16 changes: 16 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,19 @@ function fuzifyCoorinates($original_latitude, $original_longitude)
'observations_count' => $faker->numberBetween(10, 5000),
];
});


$factory->define(\App\Treet::class, function (Faker\Generator $faker) {
$appNames = ['Treesnap','FlorestaDB','HealthyWoods', 'Avid Deer', 'Eastern Forest Pests'];
$imagePaths = ["../images/logos/treesnap_logo.png","../images/logos/florestadb_logo.png","../images/logos/healthywoods_logo.png","../images/logos/aviddeer_logo.png","../images/logos/efp_logo.png"];
$urls = ["https://treesnap.org/","https://app.florestadb.org/login","https://healthywoodsapp.org/","https://aviddeer.com/","https://easternforestpests.com/"];
$randApp = array_rand($appNames, 1);

return [
'app_name' => $appNames[$randApp],
'image_path' => $imagePaths[$randApp],
'url' => $urls[$randApp],
'description' => $faker->sentence()
];
});

31 changes: 31 additions & 0 deletions database/migrations/2024_05_14_164032_create_treets_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations. /Users/chancestribling/Sites/Treesnap-website/database/migrations/2024_05_14_164032_create_treets_table.php
*/
public function up(): void
{
Schema::create('treets', function (Blueprint $table) {
$table->id();
$table->text('app_name');
$table->text('image_path');
$table->text('url');
$table->text('description');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('treets');
}
};
22 changes: 22 additions & 0 deletions database/seeders/TreetSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Treet;


class TreetSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$treets_count = 10;

factory(Treet::class, $treets_count)->create();

}
}
Binary file added public/images/logos/aviddeer_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logos/efp_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logos/florestadb_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logos/healthywoods_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logos/treesnap_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/assets/js/components/HomeJumbotron.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class HomeJumbotron extends Component {
</p>
<p>
<Link to="/partners" className={'button is-borderless'}>Meet the scientists that use TreeSnap data</Link>
<Link to={{ pathname: "https://www.youtube.com/channel/UCw46pEsdYcqwD238Wy56M3A" }} target="_blank" className={'button is-borderless ml-2 bg-gray'}><i class="fa fa-youtube mr-2" size="lg"></i> Tutorials available on YouTube</Link>
<Link to={{ pathname: "https://www.youtube.com/channel/UCw46pEsdYcqwD238Wy56M3A" }} target="_blank" className={'button is-borderless ml-2 bg-gray'}><i className="fa fa-youtube mr-2" size="lg"></i> Tutorials available on YouTube</Link>
</p>
</div>

Expand Down
18 changes: 18 additions & 0 deletions resources/assets/js/components/RecentUpdates.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, {Component} from 'react'

export default class RecentUpdates extends Component {
render() {
return (
<div className="recent-updates">
<div className="container">
<h2 className="title is-3 text-white has-text-centered">Recent Updates</h2>
<div className="update-marquee">
<div className="update-card">
<h1>The Hemlock survey has been updated to support the Lingering Hemlock Protocol</h1>
</div>
</div>
</div>
</div>
)
}
}
Loading

0 comments on commit ec22cbe

Please sign in to comment.