-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
256 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gitlab | ||
|
||
import ( | ||
"gitlab.com/leanlabsio/kanban/models" | ||
"gitlab.com/leanlabsio/kanban/modules/gitlab" | ||
) | ||
|
||
// UploadFile uploads file to gitlab | ||
func (ds GitLabDataSource) UploadFile(boardID string, file models.UploadForm) (*models.File, error) { | ||
body, err := file.File.Open() | ||
res, err := ds.client.UploadFile(boardID, file.File.Filename, body) | ||
|
||
return newFileFromGitlab(res), err | ||
} | ||
|
||
// newFileFromGitlab creates new local file from gitlab file | ||
func newFileFromGitlab(f *gitlab.File) *models.File { | ||
return &models.File{ | ||
Alt: f.Alt, | ||
URL: f.URL, | ||
Markdown: f.Markdown, | ||
} | ||
} |
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,15 @@ | ||
package models | ||
|
||
import "mime/multipart" | ||
|
||
// File represents uploaded file | ||
type File struct { | ||
Alt string `json:"alt"` | ||
URL string `json:"url"` | ||
Markdown string `json:"markdown"` | ||
} | ||
|
||
// UploadForm represents file uploaded | ||
type UploadForm struct { | ||
File *multipart.FileHeader `form:"file"` | ||
} |
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,47 @@ | ||
package gitlab | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"mime/multipart" | ||
"net/http" | ||
) | ||
|
||
// File represents uploaded file to gitlab | ||
// | ||
// Gitlab API docs: http://docs.gitlab.com/ee/api/projects.html#upload-a-file | ||
type File struct { | ||
Alt string `json:"alt"` | ||
URL string `json:"url"` | ||
Markdown string `json:"markdown"` | ||
} | ||
|
||
// UploadFile uploads file to gitlab project | ||
// | ||
// Gitlab API docs: http://docs.gitlab.com/ee/api/projects.html#upload-a-file | ||
func (g *GitlabContext) UploadFile(projectID, name string, file io.Reader) (*File, error) { | ||
path := getUrl([]string{"projects", projectID, "uploads"}) | ||
|
||
body := new(bytes.Buffer) | ||
writer := multipart.NewWriter(body) | ||
part, err := writer.CreateFormFile("file", name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = io.Copy(part, file) | ||
|
||
err = writer.Close() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, _ := http.NewRequest("POST", path, body) | ||
req.Header.Set("Content-Type", writer.FormDataContentType()) | ||
|
||
var ret File | ||
if _, err := g.Do(req, &ret); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ret, nil | ||
} |
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,25 @@ | ||
package board | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gitlab.com/leanlabsio/kanban/models" | ||
"gitlab.com/leanlabsio/kanban/modules/middleware" | ||
) | ||
|
||
// UploadFile uploads file to datasource provider | ||
func UploadFile(ctx *middleware.Context, f models.UploadForm) { | ||
res, err := ctx.DataSource.UploadFile(ctx.Params(":board"), f) | ||
|
||
if err != nil { | ||
ctx.JSON(http.StatusUnauthorized, &models.ResponseError{ | ||
Success: false, | ||
Message: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, &models.Response{ | ||
Data: res, | ||
}) | ||
} |
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,45 @@ | ||
(function(angular){ | ||
'use strict'; | ||
|
||
angular.module("gitlabKBApp").component("mdEditor",{ | ||
templateUrl: CLIENT_VERSION + "/assets/html/board/views/md-editor.html", | ||
controller: 'MdEditorController', | ||
bindings: { | ||
description: '=', | ||
rows: '=' | ||
} | ||
}).controller('MdEditorController', [ | ||
'FileUploader', | ||
'$state', | ||
'AuthService', | ||
'BoardService', | ||
function(FileUploader,$state, AuthService, BoardService){ | ||
var ctrl = this; | ||
ctrl.project_path = $state.params.project_path; | ||
ctrl.progress = false; | ||
ctrl.uploader = new FileUploader({ | ||
autoUpload: true | ||
}); | ||
|
||
BoardService.get($state.params.project_path).then(function(board) { | ||
ctrl.uploader.url = '/api/boards/' + board.project.id + '/upload'; | ||
}); | ||
|
||
ctrl.uploader.headers = { | ||
'X-KB-Access-Token': AuthService.getCurrent() | ||
}; | ||
|
||
ctrl.uploader.onProgressItem = function(item) { | ||
ctrl.progress = true; | ||
}; | ||
|
||
ctrl.uploader.onCompleteItem = function(item, response, status, headers) { | ||
if (ctrl.description == undefined) { | ||
ctrl.description = ''; | ||
} | ||
ctrl.progress = false; | ||
ctrl.description += '\n' + '\n' + response.data.markdown; | ||
}; | ||
} | ||
]); | ||
}(window.angular)); |
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
Oops, something went wrong.