diff --git a/generalprofile.php b/generalprofile.php index ba6e5a1..588980b 100644 --- a/generalprofile.php +++ b/generalprofile.php @@ -8,6 +8,10 @@ +
+
+
+
diff --git a/js/editphoto.js b/js/editphoto.js index dc576ff..81be727 100644 --- a/js/editphoto.js +++ b/js/editphoto.js @@ -14,32 +14,45 @@ let newTags = []; let removedTags = []; errorCounter = 0; let bw = []; +let comment = 0; loadServerTags(); loadBadWords(); +$.ajax({ + url: "http://localhost:3000/comments?photoId=" + id, + success: function (data) { + for (let a of data) { -function loadBadWords(){ + comment++; + } + }, + error: function (error) { + console.log("Ha ocurrido un error: " + error.toString()); + } +}); + +function loadBadWords() { $.ajax({ url: "http://localhost:3000/badwords", - success: function(data){ + success: function (data) { - for(i of data){ + for (i of data) { bw.push(i.word); } }, error: function (error) { console.log("Ha ocurrido un error: " + error.toString()); } - }).done(function(){console.log(bw)}); + }).done(function () { console.log(bw) }); } -function loadServerTags(){ +function loadServerTags() { $.ajax({ url: "http://localhost:3000/tags", @@ -50,16 +63,16 @@ function loadServerTags(){ }); } -function processServerTags(data){ +function processServerTags(data) { - for (tag of data){ + for (tag of data) { tagsServidor.push(tag.tag); tagsId.push(tag.id); } - + } // Función auxiliar para convertir un mensaje de error a un elemento HTML // Si se usa mucho, sería aconsejable ponerla en un archivo común. @@ -90,48 +103,60 @@ function showPhoto(photo) { $("#image").attr("src", photo.url); $("#description-input").val(photo.description); - + let cnt = 0; - for(tag of photo.tags){ + for (tag of photo.tags) { console.log(tag); oldTags.push(tag); let aux = -1; - - for (var z= 0; z ${tagsServidor[aux]}`); - cnt++; - - - } - else{ - $("li").last().append(`${tagsServidor[aux]}`); - cnt++; + $("#tags").append(`
  • ${tagsServidor[aux]}
  • `); + cnt++; + + + } + else { + + $("li").last().append(`${tagsServidor[aux]}`); + cnt++; + } + $("span.badge").after(" "); + + tagsAux.push(tagsServidor[aux]); } - $("span.badge").after(" "); - tagsAux.push(tagsServidor[aux]);} - } $("#tags-input").val(photo.tags.join(", ")); console.log(oldTags); } // Ejecutaremos loadPhoto cuando la página esté lista -$(loadPhoto); +if(localStorage.token!=null){ + $(loadPhoto); + +} +else{ + $("#errors-container").append( + getError("¡Tienes que estar logeado para acceder a esta página!") + ); + + +} + @@ -142,204 +167,231 @@ $("#photo-form").submit(function (event) { $("#errors-container").empty(); let description = $("#description-input").val(); - let tags = tagsAux; + if (description.trim().length != 0) { - let tags_ = []; - - for( n = 0 ; n 0) { + $("#errors-container").append( + getError("¡No puedes poner privada una foto con comentarios!") + ); } - } + else { - for( n = 0 ; naux){ - aux = l; } } - aux++; - tagsId.push(aux); - newTags.push(aux); + for (n = 0; n < cntNewTag + 1; n++) { - let tag = { - tag: w.val(), - - }; - let blbw = true; - for (zk of bw){ + let p = "#input-new-tags-" + n; - if (w.val().includes(zk)){ + let w = $(p); - blbw = false; - } - } - if(blbw){ - $.ajax({ - - url: "http://localhost:3000/tags", - method: "POST", - data: JSON.stringify(tag), - contentType: "application/json", - success: true, - error: function(){ - $("#errors-container").append( - getError("Ha habido un error") - ); - }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario - });} - } - else if (tagsServidor.includes(w.val())&& !(tags.includes(w.val()))){ - tags.push(w.val()); - tags_.push(w.val()); + if (w.val() != null && $.trim(w.val()).length !== 0 && w != undefined && !(tags.includes(w.val())) && !(tagsServidor.includes(w.val()))) { - } - } + tags.push(w.val()); + tags_.push(w.val()); + tagsServidor.push(w.val()); + let aux = 0; + for (l of tagsId) { - let aux2 = tags_; - tags = []; - + if (l > aux) { + aux = l; + } + } - for (p of newTags){ + aux++; + tagsId.push(aux); + newTags.push(aux); - tags.push(p); - } - + let tag = { + tag: w.val(), - /*for(var numero = 0; numero
    @@ -369,18 +421,18 @@ function createNewTagBox(){ $("#new-tags-list").append(html); - - - - + + + + } -function createTagBox(){ +function createTagBox() { cntTag++; - + let html = `
  • @@ -396,8 +448,8 @@ function createTagBox(){ $("#tags-list").append(html); - for(numero = 0; numero${exTags[numero]}`); } @@ -405,7 +457,7 @@ function createTagBox(){ -function processTags(){ +function processTags() { $.ajax({ @@ -417,16 +469,16 @@ function processTags(){ }); } -function setTags(data){ +function setTags(data) { for (tag of data) { - - let html =``; + + let html = ``; $("#input-tags-0").append(html); - + exTags.push(tag.tag); } @@ -437,11 +489,24 @@ function setTags(data){ } -function del(s){ +function del(s) { $(s).parent().parent().parent().remove(); - + +} +if(localStorage.token!=null){ + processTags(); + } -processTags(); + +$(document).ready(function () { + + if(localStorage.token==null){ + $("#photo-form").empty(); + + } + +}); + diff --git a/js/edittags.js b/js/edittags.js index 4132e14..536fcb7 100644 --- a/js/edittags.js +++ b/js/edittags.js @@ -133,7 +133,7 @@ function apply() { for (z of bw) { - if (new_tag.includes(z)) { + if (new_tag.toLowerCase().includes(z)) { palabrota = true; @@ -164,6 +164,7 @@ function apply() { if (response.ok) { window.location.href = "index.php"; } else { + removeError($("#errors-container")); $("#errors-container").append(getError(response.statusText)); } }).catch(console.log); @@ -198,6 +199,7 @@ function apply() { } function getError(message) { + return ( "
    -

    Hi @loremIpsum

    +

    My pictures!



    diff --git a/photo_detail.php b/photo_detail.php index 7ff03fa..08e59fb 100644 --- a/photo_detail.php +++ b/photo_detail.php @@ -8,13 +8,14 @@ - -
    - -
    +
    +
    + + +
    @@ -32,7 +33,7 @@

    -
    @user
    +


    diff --git a/photo_edit.php b/photo_edit.php index bd279b2..b2f55d4 100644 --- a/photo_edit.php +++ b/photo_edit.php @@ -15,6 +15,10 @@

    EditPhoto

    +
    +
    +
    +

    diff --git a/register.php b/register.php index 4d8b132..a71cf4c 100644 --- a/register.php +++ b/register.php @@ -103,18 +103,7 @@ class="form-check-label col-md-3 offset-md-3 col-form-label commontext col-form-
    -
    - -
    - - - - -
    - -
    +