Skip to content

Instantly share code, notes, and snippets.

enum MediaType
{
case image
case video
case audio
case document
}
struct Media
{
class DragDropAreView: NSView {
private var fileTypeIsOk = false
private var acceptedFileExtensions = ["jpg","png","doc","docx","pdf","mov","mp4","mp3"]
var delegate: DragDropViewDelegate?
var isReceivingDrag = false {
didSet {
needsDisplay = true
}
import Cocoa
class CollectionViewItem: NSCollectionViewItem {
override func viewDidLoad() {
super.viewDidLoad()
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.lightGray.cgColor
}
override func viewDidLoad() {
super.viewDidLoad()
dragDropAreaView.delegate = self
setupView()
}
override func viewDidAppear() {
let flowLayout = NSCollectionViewFlowLayout()
flowLayout.itemSize = NSSize(width: 160.0, height: 120.0)
func createDirectory(sourcePath: String, type: MediaType) {
// path to documents directory
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
if let documentDirectoryPath = documentDirectoryPath {
// create the custom folder path
var subDirectoryPath = ""
switch type
{
case .audio:
subDirectoryPath = documentDirectoryPath.appending("/audios")
@IBAction func didClickOnExploreButton(_ sender: NSButtonCell)
{
toggleViewStates(state: false)
files = [String:Media]()
switch sender.tag {
case 101:
getFilesFromDoucmentDir(type: .image)
case 102:
getFilesFromDoucmentDir(type: .video)
case 103:
extension HomeViewController: DragDropViewDelegate
{
func draggedMediaType(type: MediaType, url: NSURL) {
switch type {
case .audio:
self.createDirectory(sourcePath: url.absoluteString!, type: .audio)
case .video:
self.createDirectory(sourcePath: url.absoluteString!, type: .video)
case .image:
self.createDirectory(sourcePath: url.absoluteString!, type: .image)
@pallavtrivedi03
pallavtrivedi03 / movie.js
Created January 7, 2019 13:32
MongoDB model for Movie
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const movieSchema = new Schema({
title: {
type: String,
required: true
},
year: {
@pallavtrivedi03
pallavtrivedi03 / movie-schema.js
Created January 7, 2019 13:35
GraphQL schema for Movie
module.exports = {'movieBuildSchema':`
type Movie {
_id: ID!
title: String!
year: Int!
released: String!
genre: String!
director: String!
actors: String!
plot: String!
@pallavtrivedi03
pallavtrivedi03 / resolvers.js
Created January 7, 2019 13:54
Resolvers for Movie schema
movies: () => {
return Movie.find()
.then(movies => {
return movies.map(movie => {
return { ...movie._doc, _id: movie._doc._id.toString()}; //overwriting id
});
})
.catch(err => {
throw err;
});